您的位置:首页 > 移动开发 > IOS开发

ios 常见错误整理 持续更新

2012-10-18 16:04 246 查看

1. mutating method sent to immutable object'

从字面上理解:可变的消息发给了不可变的对象。比如NSDictionary类型的对象调用setValue方法.应该把NSDictionary 改成NSMutableDictionary类型。

2.Local declaration of 'content' hides instance variable

一般是函数里面定义的变量和class属性变量重名了。很少有和系统变量重名的情况。

3.unrecognized selector sent to instance

大部分情况下是因为对象被提前release了,在不希望他release的情况下,指针还在,对象已经不在了。

很多时候,是因为init初始化函数中,对属性赋值没有使用self.foo赋值,而是直接对foo赋值,导致属性对象没有retain(心里以为retain了),而提前释放。


4.使用ASIHTTPRequest编译不通过

原因是一些类库没有加进去。把这些库加进去CFNetwork, SystemConfiguration, MobileCoreServices, and libz.dylib

5.添加在UIView中的UIButton 单击不起作用

原因是UIbutton的frame超出了UIView的frame范围。事实上UIView并没有设置frame,设置完后( 范围一定要在UIButton之外),UIButton单击就可以了



6.当使用presentViewController和dismissPresentViewController时,如果报这个错 : while presentation is in progress ,修改方法为[mainView dismissModalViewControllerAnimated:NO]; 将参数Animated改为NO;如果报这个错while a presentation or dismiss is in
progress,试试这样


if (![[mainView modalViewController] isBeingDismissed]) {

[mainView dismissModalViewControllerAnimated:NO];

}

7.调用系统相册的时候,非常容易出现内存警告,加入红色代码就会好点:



UIImagePickerController * picker = [[UIImagePickerController alloc]init];

picker.delegate = self;

picker.allowsEditing = NO; //是否可编辑

picker.videoQuality=UIImagePickerControllerQualityTypeLow;

//摄像头

picker.sourceType = UIImagePickerControllerSourceTypeCamera;

[self presentModalViewController:picker animated:YES];

[picker release];

8.ios开发者都遇见过得错误:EXC_BAD_ACCESS 。这个和第二个比较类似。通常的调试方法就是加入NSZombieEnabled变量,加入方法自行百度。

并且开发过程中使用

[[NSNotificationCenterdefaultCenter]
来发布本地消息,这个也经常会出现EXC_BAD_ACCESS错误。这个时候只需要在你的view活着viewControllers的dealloc的方法里面加入

[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"yourNotification"object:nil];就ok了

9.遇见一个蛋疼的问题"linker command failed with exit code 1 (use -v to see invocation)" 。翻遍了找不到原因。然后还有这样的警告


duplicate symbol _OBJC_CLASS 。原来是在导入某个类的时候导入.m文件,而不是.h文件

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: