Highlights of IOS development study notes Solutions

Source: Internet
Author: User

IOS developmentThe solution to the problem highlights of Study Notes is described in this article.UITextField,UITableView,NSPredicateTo solve some problems, let's take a look at the details.

Use a regular expressionUITextFieldAccept the specified value. Only positive integers starting with non-zero can be entered. Use the following code.

 
 
  1. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:  
  2.    (NSRange)range replacementString:(NSString *)string{      
  3.       NSString *result = [textField.text stringByReplacingCharactersInRange:range withString:string];      
  4.       if ([result length] == 0) return YES;   
  5.       // Allow delete all character which are entered.          
  6.       NSString *regex = @"^[0-9]*[1-9][0-9]*$";      
  7.       NSPredicate *prd = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];      
  8.       return [prd evaluateWithObject:result]; 

UITableViewProblem encountered when setting the background to transparent UITableView set the background color to clearColor and the type to Grouped. The four corners of each Group are black. Solution:

Write in viewDidLoad:

 
 
  1. TableView.backgroundView = nil;  
  2. TableView.backgroundColor = [UIColor clearColor];  
  3. TableView.opaque = NO; 

Display emoticon list in UITextField: http://pukupi.com/post/1964

For example, smile:

 
 
  1.   
  2. label.text = @"\ue415";  

The effect is as follows:

 

How to remove NSLog output when compiling and releasing a version

You only need to add it to the pch file. The __optimize _ compilation option is available only for the released version. Therefore, you can see the Log when compiling and debugging the version, but there is no Log for the released version.

 
 
  1. #ifndef __OPTIMIZE__#define NSLog(...) NSLog(__VA_ARGS__)#else#define NSLog(...) {}  
  2. #endif 

NSPredicate notes

 
 
  1. NSPredicate *p = [NSPredicate predicateWithFormat:@"SELF like[c] %@", @"aa*bb"]; 

Where: SELF is case sensitive.

Aa * bb uses a wildcard, And the * number can only be written in a variable.

 
 
  1. @"SELF like[c] %@*%@", @"aa", @"bb" 

The string is enclosed in quotation marks, but it is not used here. NSPredicate is automatically added.

Test Boolean Value

 
 
  1. NSPredicate *p = [NSPredicate predicateWithFormat:@"self == NO"];   
  2. BOOL b1 = [p1 evaluateWithObject:[NSNumber numberWithBool:NO]];    
  3. NSPredicate *p2 = [NSPredicate predicateWithFormat:@"self == %@",   
  4. [NSNumber numberWithBool:NO]];      
  5. BOOL b2 = [p2 evaluateWithObject:[NSNumber numberWithBool:NO]]; 

Dynamic attribute name

The followingNSPredicate

 
 
  1. NSPredicate *p = [NSPredicate predicateWithFormat:@"name = %@", @"Jimmy"]; 

Sometimes we may want to change the name keyword into a variable and write it out, so that we can write a more general NSPredicate. So I naturally thought of the following code:

 
 
  1. NSString *key = @"name";     
  2.  NSString *value = @"Jimmy";      
  3.  NSPredicate *p = [NSPredicate predicateWithFormat:@"%@ = %@", key, value]; 

In this way, we can change the value of key and value before executing the third sentence to make it more generic. The idea is good, but this is wrong. As mentioned above,NSPredicateTo automatically add quotation marks, the final format should be @ "'name' = 'Jimmy '". Obviously not. What you need to do is:

 
 
  1. NSString *key = @"name";      
  2. NSString *value = @"Jimmy";      
  3. NSPredicate *p = [NSPredicate predicateWithFormat:@"%K = %@", key, value]; 

Summary:IOS developmentI hope this article will help you with the introduction of the problem highlights solution!

Related Article

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.