iPhone开发知识总结 上篇

移动开发 iOS
iPhone开发知识总结 上篇是本文要介绍的内容,主要讲述的是iphone应用开发中Atomic 和 nonatomic 属性的理解,来看详细内容。

iPhone开发知识总结 上篇是本文要介绍的内容,主要讲述的是iphone开发应用中Atomic nonatomic 属性的理解,来看详细内容。

1、关于不同分辨率的屏幕显示问题 
 
iphone 3 和 4分辨率各不相同。加载图像的时候只需要指定基本的文件名,例如:pic.png根据不同分辨率,如果在iphone 4 上会自动加载pic@2x.png(如果存在)。

2、关于Atomic 和 nonatomic 属性的理解

atomic的访问控制器只用在没有垃圾回收的环境中。

使用atiomic能保证线程安全的,保证一个属性的get/set在一个线程中必须完成之后才能有其他的线程访问它。

  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.   

Atomic版本加了一个锁保证线程安全的,atomic保证userName方法获得的不是一个释放过的值。

3、使用归档程序复制对象(深复制)

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

4、在iphone开发中,设置navigationController中返回按钮的标题,默认为前一个视图中标题的title,

如果设置,在前一个视图中写下:

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

5、在table view 中加入手势或者事件触摸机制,需要实现方法

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

应该如下判断用户触摸的是哪一个cell

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

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

UIViewController的这个方法很有意思,一般parent view controller都有责任调用此方法来消除其通过presentModalViewController:animated: 方法展现的modal view controller。但是如果你在modal view controller中调用此方法,modal view controller会自动的把此消息转发给parent view controller。

小结:iPhone开发知识总结 上篇的内容介绍完了,如果你对iphone开发感兴趣的话,请参考 iPhone开发知识总结 下篇的相关内容,***希望本文能对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-08-15 10:45:11

iPhone开发delegate

2011-07-19 09:46:38

2011-08-11 10:16:23

iPhoneUIView视图

2011-08-04 16:17:39

iPhone 开发工具

2021-06-26 10:03:35

Python框架Flask

2009-01-11 09:14:45

Javascript开发总结

2020-04-22 13:33:30

iPhone苹果3C制造业

2012-05-17 11:45:12

iPhone

2021-08-23 10:12:41

鸿蒙HarmonyOS应用

2011-07-19 10:42:41

iPhone 应用程序 模型

2013-01-06 09:52:43

SQLite

2013-04-09 16:04:06

iOS开发SQLite知识总结

2021-08-26 10:25:04

JavaScript进阶操作 前端

2011-07-06 17:53:40

iPhone SDK Xcode

2011-08-11 11:37:34

iPhone内存

2012-04-26 21:56:59

iPhone

2011-06-17 16:47:12

Qt Eclipse Windows

2011-07-25 18:02:51

iPhone LibFetion 移植

2021-04-12 10:00:47

Sqlite数据库CMD

2016-12-21 09:55:55

面试JavaScrip总结
点赞
收藏

51CTO技术栈公众号