iOS开发中遇到的问题

  1. tableview 或者 collectionview 点击 cell 时不执行 didselect 方法,原因有可能是因为当前 view 添加有 tap 手势,造成冲突.
    解决办法:实现手势代理,根据点击的 view 确定是否响应手势.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    //cell 上有个 label, 点击 cell 的时候,实际点击的是 label
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UILabel"]) {
        return NO;
    }
    return YES;
}

2.iOS 10,UIWebview 加载网页的时候,底部会出现黑边,加载完后黑边消失,解决方法

self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor whiteColor];

3.terminate_handler unexpectedly threw an exception

1.对不可变对象进行了改变
2.有可能是删除了xib 中拉出来的属性,但没有对xib中的对应控件删除联系

4.warning: directory not found for option“XXXXXX”

1.选择工程, 编译的 (targets)
2.选择 Build Settings 菜单
3.查找 Library Search Paths 和 Framework Search Paths, 删掉编译报warning的路径即OK

5.声明数组属性的时候最好用strong,如果用copy,那么对于可变数组(mutable array)

self.dataArray = [NSMutableArray arrayWithArray:@[@"1", @"2"]];
如果dataArray为可变数组,那么使用self.dataArray将得到一个不可变数组.

6.编译警告:”no rule to process file ‘xxx.h’ for …."

解决方案:在[Build Phases] ->[Compile Source]里找到'xxx.h'文件删除即可

7.编译警告:This file is set to build for a version older than the project deployment target. Functionality may be limited
解决方案:选中xib文件,然后如下操作


20151106142334918.png

8.loaded the "XXXView" nib but the view outlet was not set.解决方案

1, 打开nib文件
2, 点击"File's Owner", 按command+4,设置Class为xxxViewControler
3, 按Control+"Files's Owner", 里面有个默认的IBOutlet变量view, 看一下后面有没有做关联,如果没有就拉到下面的View和视图做个关联

9.Could not load NIB in bundle: 'NSBundle (loaded)' with name 'CurrentCell'

This error can occure when you rename some files outside XCode. 
To solve it you can just remove the files from your project (Right Click - Delete and "Remove Reference")
You re-import the files in your project and everything will be ok !

10.cell中有button的时候,滑动的时候button上文字出现闪烁,把button的类型改为 custom 即可

11.“APP的名字” was compiled with optimization - stepping may behave oddly; variables may not be available.

出现这种信息多数是因为赋值时某个值是 nil 造成的

12.自定义tableView的header

有时候我们想自定义UITableView的headerView,于是重写代理方法:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
但是在运行程序的时候发现该方法不执行,这时我们还需要重写一个代理方法:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
这个方法是用来指定headerView的高度的。

13.自定义rightitems时,如果使用图片,图片会被渲染成蓝色.解决办法如下

UIBarButtonItem * weChatItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"im_weChat"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(copyWeChat)];
图片不渲染,始终使用原图
[[UIImage imageNamed:@"im_weChat"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

你可能感兴趣的:(iOS开发中遇到的问题)