zoukankan      html  css  js  c++  java
  • ios学习笔记之1 通讯录应用练习 smallelephant_A

    今天写了一个比较简易版的通讯录应用

    主要用到的知识有

    1,UITableView的数据源,代理方法等

    UItableview数据源主要方法

    必须实现的方法:

    (1)row的数量

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

    (2)每个cell里面的内容

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

     以下是option(可选)实现的内容

    (1)section的数量

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;              // Default is 1 if not implemented

    (2)header的标题 返回一个字符串

     - (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different

    (3)footer的标题 返回一个字符串

     - (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

    (4)是否能够编辑行 返回一个布尔值

     - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

    (5)是否能移动行

     - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

     (6)section索引 返回数组

    - (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView __TVOS_PROHIBITED;                                                    // return list of section titles to display in section index view (e.g. "ABCD...Z#")

     (7)告诉表格哪一个section的index对应着section

    - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index __TVOS_PROHIBITED;  // tell table which section corresponds to section title/index (e.g. "B",1))

     (8)行处于编辑状态(能删除或者插入)

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

    (9)移动行

     - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;

    2,新api UIAlertController的应用

    基本代替了以前的UIAlertview

    参考地址 http://www.cocoachina.com/ios/20141126/10320.html

    3,plist写入数据并通过‘字典转模型’的方法读出

    例:

    -(void)loadData{

     

        if (!_arrayContacts) {

            NSString *path = [[NSBundle mainBundle]pathForResource:@"contactGroup.plist" ofType:nil];

            NSArray *arr = [NSArray arrayWithContentsOfFile:path];

            

            NSMutableArray *array = [[NSMutableArray alloc]init];

            for(NSDictionary *dict in arr)

            {

                ContactGroup *group = [ContactGroup contactGroupWithDictionary:dict];

                [array addObject:group];

            }

            

            _arrayContacts = [array copy];

            

        }

     }

    4,lazy 初始化

    懒加载:

    懒加载也叫延迟加载 ,在需要的时候才加载,写的是get方法

    懒加载的好处:不必将代码都写在viewdidload里面,增加了代码的可读性

           每个控件的getter 方法分别负责各自的实例化过程,代码彼此之间的独立性强,松耦合。

    5,工厂方法

    例如

    -(instancetype)initwithDict:(NSDictionary*)dict;

    +(instancetype)heroWithDict:(NSDictionarty*)dict;

    6,NSPredicate的应用

    谓词 指定的过滤器

    参考网址 http://www.cnblogs.com/hxwj/p/4827561.html 

    7,UItableviewcell的样式

    四种  http://blog.csdn.net/crazyzhang1990/article/details/12503163

    虽然是很基础的知识,但是很重要

    8,UIsearchbar的应用以及代理方法的掌握

    介绍几个UIsearchbar 的代理方法

     (1)return NO 就是不成为第一响应者 即不起作用

    - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar;                      // return NO to not become first responder

    (2)开始编辑 在开始编辑的时候用到

    - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar;                     // called when text starts editing

    (3)return NO 表示不能取消第一响应者

    - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar;                        // return NO to not resign first responder

    (4)当文本编辑结束时起作用

    - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar;                       // called when text ends editing

    (5)当文本被改变的时候其作用 因为包含清除的情况 所以需要if语句考虑到

    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;   // called when text changes (including clear)

    (6)在文本改变的时候应用

    - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text NS_AVAILABLE_IOS(3_0); // called before text changes

     (7)在点击搜索按钮的时候被调用

    - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;                     // called when keyboard search button pressed

    (8)bookmark被点击的时候调用

    - (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar __TVOS_PROHIBITED; // called when bookmark button pressed

    (9)取消按钮被点击时候调用

    - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar __TVOS_PROHIBITED;   // called when cancel button pressed

    (10)搜索结果按钮被点击时候调用

    - (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar NS_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED; // called when search results button pressed

     (11)选择范围键改变的时候调用

    - (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope NS_AVAILABLE_IOS(3_0);

     

    参考网址:http://www.cnblogs.com/xiaofeixiang/p/4273620.html

    9,UItableviewcell的增删移动查询

    修改主要用到的方法

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    删除和添加用到的方法

    -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

    移动用到的函数

    -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

    由于在cell是编辑状态时候有两种 所以需要判断是添加还是删除

    -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

     10,状态栏样式修改

    -(UIStatusBarStyle)preferredStatusBarStyle

    -(BOOL)prefersStatusBarHidden

    以上是今天主要学习到的内容 github上有代码 https://github.com/Disneydusunan/contact-test

  • 相关阅读:
    PAT 甲级 1115 Counting Nodes in a BST (30 分)
    PAT 甲级 1114 Family Property (25 分)
    PAT 甲级 1114 Family Property (25 分)
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
  • 原文地址:https://www.cnblogs.com/adodo/p/5191565.html
Copyright © 2011-2022 走看看