IOS 开发问题解决

来源:互联网 发布:英国美国留学对比知乎 编辑:程序博客网 时间:2024/05/21 09:22

一、刷新时,数组会越界。

      原因:比较会出现数组越界Crash的地方

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    WelfareItem *item = [_datasourceArray objectAtIndex:indexPath.row];//有可能会越界,你在下拉刷新时会用[_datasourceArray removeAllObjects],这时你又点了某个cell就会Crash

}

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    WelfareItem *item = _datasourceArray[indexPath.row];//有可能会越界,两个地方用了[tableView reloadData];后一个有[_datasourceArray removeAllObjects];前一个还没有执行完,就会Crash

}

上面代码是有可能会越界的;出现Crash也不好复现,发出去的App总是能收到几条Crash;解决这个问题也很简单代码如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    WelfareItem *item = nil;

    if (indexPath.row < [_datasourceArray count]) {//无论你武功有多高,有时也会忘记加

        item = [_datasourceArray objectAtIndex:indexPath.row];

    }

}

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    WelfareItem *item = nil;

    if (indexPath.row < [_datasourceArray count]) {

        item = [_datasourceArray objectAtIndex:indexPath.row];

    }

}

判断index.row和你当前的数组就可以解决


二、 clang: error: linker command failed with exit code 1 (use -v to see invocation){铿锵声:错误:链接器命令失败,退出码1(使用- v查看调用)}


ios开发这个错误一定少不了,现总结如下,一般这三方面的问题,如果不是哪你真可麻烦了

1.引用出错,把***.h弄成了.m,检查一下你的所有引用;

2.再就是你引用第三方的库,你添加文件是系统没有所第三方库的.m文件参入的编译中去,你向项目添加文件得注意了;

3.就是不小心添加的重复的类,向Entity之类,具体你可以看这里http://stackoverflow.com/questions/2264455/iphone-duplicate-symbol-error

顺便说一下http://stackoverflow.com/这个网站是iso开发不可少的一个网站;

4.有些frameworks没有添加进来也会出现上面的问题;

5.引用第三方库时Build settings->Linking->Other Linker Flags填写不正确。

6.架构问题

7.i386



mjrehresh用法:https://github.com/CoderMJLee/MJRefresh#上拉刷新01-默认


三、导航栏的问题

iOS7之后由于navigationBar.translucent默认是YES,坐标零点默认在(00)点  当不透明的时候,零点坐标在(064);如果你想设置成透明的,而且还要零点从(064)开始,那就添加:self.edgesForExtendedLayout = UIRectEdgeNone; 


0 0