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.
- //@property(nonatomic, retain) UITextField *userName;
- //Generates roughly
- - (UITextField *) userName {
- return userName;
- }
- - (void) setUserName:(UITextField *)userName_ {
- [userName_ retain];
- [userName release];
- userName = userName_;
- }
Now, the atomic variant is a bit more complicates:
- //@property(retain) UITextField *userName;
- //Generates roughly
- - (UITextField *) userName {
- UITextField *retval = nil;
- @synchronized(self) {
- retval = [[userName retain] autorelease];
- }
- return retval;
- }
- - (void) setUserName:(UITextField *)userName_ {
- @synchronized(self) {
- [userName_ retain];
- [userName release];
- userName = userName_;
- }
-
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)
- NSMutableArray *dataArray = [NSMutableArray arrayWithObjects:[NSMutableString stringWithString: @"one"], ....];
- NSMutableArray *dataArray2;
-
- NSData data = [NSKeyedArchiver archivedDataWithRootObject:dataArray];
- 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:
- UIBarButtonItem *temporaryBarButtonItem=[[UIBarButtonItem alloc] init];
- temporaryBarButtonItem.title=@"Back";
- self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
- [temporaryBarButtonItem release];
5. Adding a gesture or event touch mechanism to table view requires implementation.
- -(BOOL)canBecomeFirstResponder {
- return YES;
- }
Determine which cell the user is touching.
- CGPoint pinchLocation = [pinchRecognizer locationInView:self.tableView];
-
- 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!