IPhone development knowledge Summary

Source: Internet
Author: User

IPhone DevelopmentThe previous article describes the content of this article, mainly aboutIphone DevelopmentApplication in progressAtomicAndNonatomicFor more information, see.

1. Screen Display with different resolutions
 
The resolutions of iphone 3 and iphone 4 are different. When loading an image, you only need to specify the basic file name. For example, pic.png will automatically upload pic@2x.png if it exists on iphone 4 based on different resolutions ).

2. Understanding of Atomic and nonatomic attributes

Atomic access controllers are only used in environments without garbage collection.

The use of atiomic can ensure thread security and ensure that the get/set of an attribute must be completed in a thread before other threads can access it.

 
 
  1. //@property(nonatomic, retain) UITextField *userName;  
  2. //Generates roughly   
  3. - (UITextField *) userName {  
  4.     return userName;  
  5.   }   
  6. - (void) setUserName:(UITextField *)userName_ {  
  7.     [userName_ retain];      
  8.     [userName release];     
  9.     userName = userName_;  
  10.  }  

Now, the atomic variant is a bit more complicates:

 
 
  1. //@property(retain) UITextField *userName;  
  2. //Generates roughly   
  3. - (UITextField *) userName {  
  4.     UITextField *retval = nil;      
  5.   @synchronized(self) {  
  6.           retval = [[userName retain] autorelease];  
  7.    }     
  8.     return retval;  
  9.  }   
  10. - (void) setUserName:(UITextField *)userName_ {    
  11.      @synchronized(self) {       
  12.      [userName_ retain];        
  13.      [userName release];       
  14.       userName = userName_;   
  15. }  
  16.   

The Atomic version adds a lock to ensure thread security. The atomic ensures that the userName method does not obtain a released value.

3. Use the archive program to copy objects)

 
 
  1. NSMutableArray *dataArray = [NSMutableArray arrayWithObjects:[NSMutableString stringWithString: @"one"], ....];  
  2. NSMutableArray *dataArray2;  
  3.  
  4. NSData data = [NSKeyedArchiver archivedDataWithRootObject:dataArray];  
  5. dataArray2 = [NSKeyedUnarchiver unarchiveObjectWithData: data]; 

4. In iphone development, set the title of the return button in navigationController, which is the title in the previous view by default,

If set, write the following in the previous view:

 
 
  1. UIBarButtonItem *temporaryBarButtonItem=[[UIBarButtonItem alloc] init];  
  2. temporaryBarButtonItem.title=@"Back";  
  3. self.navigationItem.backBarButtonItem = temporaryBarButtonItem;  
  4. [temporaryBarButtonItem release]; 

5. Adding a gesture or event touch mechanism to table view requires implementation.

 
 
  1. -(BOOL)canBecomeFirstResponder {  
  2. return YES;  

Determine which cell the user is touching.

 
 
  1. CGPoint pinchLocation = [pinchRecognizer locationInView:self.tableView];  
  2.  
  3. NSIndexPath *newPinchedIndexPath = [self.tableView indexPathForRowAtPoint:pinchLocation]; 

6.-(void) dismissModalViewControllerAnimated :( BOOL) animated

This method of UIViewController is very interesting. Generally, parent view controller has the responsibility to call this method to eliminate its modal view controller displayed through the presentModalViewController: animated: method. However, if you call this method in modal view controller, modal view controller automatically forwards the message to the parent view controller.

Summary:IPhone DevelopmentThe content in the previous article is complete.Iphone DevelopmentIf you are interested, please refer to the iPhone development knowledge to summarize the relevant content in the next article, and finally hope this article will help you!

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.