解决[__NSArrayM objectAtIndex:]: index 0 beyon Objective-C异常Bug方法

*** Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]‘

原因:

在项目开发中有时会碰到类似以上提示,造成程序崩溃原因是

出现该问题一般是在我们的列表tableview中,计数

[[[[_dataList objectAtIndex:section] objectForKey:@"subs"] objectAtIndex:0] objectForKey:@"section"]; 时其键值未做判断是否为空处理造成的

程序中声明用到的:

NSMutableArray *_dataList; 变量运行时先通过代理载入tableview视图时是空的就停止,造成后续载入数据无法进行;

我是的是出现在:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section:

方法:

只要在有上述类似一维或二维键值的地三元判断一下就可以,方法如下:

[_dataList count]?[[[[_dataList objectAtIndex:section] objectForKey:@"subs"] objectAtIndex:0] objectForKey:@"section"]:@"";

[_dataList count]?[[[_dataList objectAtIndex:section] objectForKey:@"subs"] count]:0;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值