Example of iOS ui--Address Book key knowledge technology point accumulation

Source: Internet
Author: User

Instance of Address Book key knowledge technology point accumulation

Effect Show:

Knowledge point 1 about the login button whether or not the text content is clickable

To listen to the contents of the text box, when the account number and password have value, the login button can be clicked.

第一种思路:    用代理的方式去监听文本框的内容改变        在这里前提是:这个控件有代理相关的协议,以及这个控件具有delegate属性,比如UITableView有数据源协议和代理协议,当然也会有数据源属性和delegate代理属性。        所以使用代理,就是使用这个控件代理协议中的响应控件的方法。比如UITableView中代理协议就有响应选中第几行能获取行数的方法。

And then here the first idea is that the reason for this is that there is no proper and correct method for the proxy protocol, and the only way to respond to the editing state is:

 //这个方法第二次才会来,所以不能在这个方法当中进行判断. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{  NSLog(@"%@",self.accontTextF.text);     NSLog(@"%@",textField.text); return YES;  } 也就是当我们编辑输入第一个字符是不调用这个方法的,当输入第二个字符才会响应

My first thought was complicated: I was going to implement the agent from the bottom. For example, let inherit from the TextView of the sub-class internally write good business method, and in this method to write a proxy object to follow the protocol implementation of the method, but also to let this TextView sub-class object business method at any time can hear the text box itself edit state, simply say, when the text began to edit, The method of executing this business method and then further executing the proxy. In order to be able to listen, the text box state, either is the Addtag method, or uses the TextView Proxy protocol method. So I went back to the external listening situation.

The control custom agent that has the listener event if it is not with its own proxy protocol method, it will use the addtag of the control ... The method. So it is not advisable to ask for easy.

                第二种思路:    有这样的事件可以被监听:UIControlEventEditingChanged 编辑状态            为文本框添加事件监听的方法,当文本框开始编辑的时候,触发相关的方法,方法里就是self.btn.enabled = ...    

Code

......略......        //第二种思路:和按钮一样,给文本框添加事件的方式.    //给账号添加事件    [self.accontTextF addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];        //给密码添加事件    //都让它们响应一个方法    [self.pwdTextF addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];            }//当文本框开始编辑时调用,这样可以时刻坚听文本框的内容- (void)textChange{    //账号和密码都有值时,登录按钮才能够点击.    NSLog(@"%@",self.accontTextF.text);    //第一种判断方法:    /***     if (self.accontTextF.text.length && self.pwdTextF.text.length) {     self.loginBtn.enabled = YES;     }else{     self.loginBtn.enabled = NO;     }     */        //第二种判断方法    self.loginBtn.enabled = self.accontTextF.text.length && self.pwdTextF.text.length;    }......略......
Knowledge Point 2 project file Modular management details

Knowledge point 3 on the use of Uiactionsheet

Although it appears to expire on the Apple API, it can be used and is likely to be encountered in company projects.

Knowledge Point 4

About Segue

On the code:

//segue线准备时会调用这个方法,//一般都在这个方法当中进行传值.-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{    //    [segue.sourceViewController.navigationController pushViewController:segue.destinationViewController animated:YES];}
Knowledge point 5 Passing user name (Shun Chuan)

Knowledge point 6 about setting the details of the navigation bar return

Figure 2

Knowledge point 7 data inversion the first method, by passing the controller way:
第一种方案,实现逆传数据,但是第一种方案两个类之间的耦合性太强,要互相的引用,在我们开发当中要做到低耦合,高内聚.所以不使用第一种方案.     传递数据的步骤:     1.目录控制器定义好要接收的属性.     2.拿到目录控制器.     3.把数据传递给目标控制器的属性.
高耦合分析:因为-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{    AddViewController* addVc = segue.destinationViewController;    addVc.contactVc = self;}在这个方法中,是可以通过Segue获取下一个目标控制器的对象。也就是说可以在下一个目标控制器的对象的类中添加一个当前所在对象的引用(同时也需要import导入当前对象的类),然后在这个方法中将自己传递过去:    addVc.contactVc = self;又因为在这里,需要AddViewController* addVc = segue.destinationViewController;获取下一个对象,所以这里需要导入import这个对象的类

In summary: The classes of two objects are imported, that is, referencing each other, so that the two objects are closely related, and high coupling, which is obviously very bad.

The second method, through the proxy way < the first agent;:

First Analysis:

仅有的两个类:A控制器 -segue-> B控制器(A控制器转场到B控制器)业务需求:将B控制器获取的数据所包装成的模型对象逆传给A控制器。

< The following statement uses some pseudo-code, but it should be easy to understand >

未使用代理模式:    这个业务逻辑应该由B控制器处理,也就是[B sendModel:model toVC:A]。    因为,数据模型model是由B产生,最终传递到A进行处理。
也就是说:本来应该B自己做的事情,现在B需要代理来帮忙做这个事情:
既然需要将数据传递给A,何不如试试用A作为B的代理,然后直接将数据传递给自己使用。这个就好比:本来我要亲自递苹果给我的妹妹吃,然后因为我很忙,要敲代码,现在妹妹亲自到我这拿苹果自己去吃了。在这里,妹妹亲自来拿苹果已经代理我做了传递苹果的事情。

The technical point here is the code:

//自动执行Segue时,也会来到prepareForSegue这个方法.//准备执行Segue线时调用.-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{        XMGAddViewController *addVC = segue.destinationViewController;    //它为添加控制器的代理,要遵守相应的协议.    addVC.delegate = self;    }
The third method, through the proxy way < the second agent;:

Create a third-party mediation agent to proxy the data delivery.

The fourth method, through a singleton pattern:

Then directly on the final source download: Link: http://pan.baidu.com/s/1gdRsIlX Password: c8bp

Knowledge point 8 The actual use difference between the two methods of creating UITableViewCell based on ID

Method 1 for creating the cell:

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];

Method 2 for creating the cell:

Regardless of the situation encountered above two methods should pay attention to the difference:

方法1是必须需要storyboard有设置ID的cell模板,然后根据这个ID对应的cell模板创建当前indexPath对应的cell。如果不设定程序运行会在这里奔溃。方法2是代码创建,而且仅仅是根据当前设置的style样式创建cell,然后设置ID,以备循环利用。这时候在storyboard的cell模板可以不用设定ID。

Other than that

因为方法1是直接从storyboard上的cell模板加载创建的当前indexpath位置的cell,这个cell的属性样式是可以直接在storyboard上设置。然后方法2因为是自己代码创建的cell对象,比如accessoryType要自己代码设定:cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;否则不会显示有自己想要有的这个accessoryType属性(就是右边带个箭头指示)。
Knowledge Point 9 start keyboard set to numeric keypad

Examples of iOS ui--contacts key knowledge technology point accumulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.