UITableView 避免奔溃的数组越界处理方法
2015-05-09 12:05
681 查看
0x7403d 0x3b36cab7) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) 这个方法objectAtIndex:的说明 - (id)objectAtIndex:(NSUInteger)index Description Returns the object located at the specified index. If index is beyond the end of the array (that is, if index is greater than or equal to the value returned by count), an NSRangeException is raised.超出了界限就会抛出异常 Parameters index An index within the bounds of the array. 我们可以写一个类目来避免数组越界后直接崩溃的情形(或许崩溃是最好结果,但我们有时候可以直接根据判断数组取值为nil避免崩溃),代码如下: ////NSArray+YXInfo.h//BeyondTheMark////Copyright (c) 2014年 Y.X. All rights reserved.//#import <Foundation/Foundation.h>@interface NSArray (YXInfo)- (id)objectAt:(NSUInteger)index;@end ////NSArray+YXInfo.m//BeyondTheMark////Copyright (c) 2014年 Y.X. All rights reserved.//#import "NSArray+YXInfo.h"@implementation NSArray (YXInfo)- (id)objectAt:(NSUInteger)index{ if (index < self.count) { return self[index]; } else { return nil; }}@end 实现原理超级简单呢:)
相关文章推荐
- iOS隐藏UITableView多余分割线快速处理方法
- UITableView 显示大量网络数据时怎样处理反应过慢的方法
- uitableview处理section的不悬浮,禁止section停留的方法
- iOS 数组越界处理方法总结
- UITableView 删除最后一行 奔溃错误处理方法
- java.lang.ArrayIndexOutOfBoundsException(数组越界)处理方法
- iosiOS开发之UITableView分割线不顶左解决方法
- ios之UITableView批量选中cell并实现删除cell的简单方法
- java.lang.NoSuchMethodError: jxl.write.WritableSheet.setRowView(ILjxl/CellVi 的处理方法
- IOS学习之——UITableView 实现数据源的方法
- JNI学习笔记:(1)开篇(2)本地代码访问Java代码 (3)本地方法取得Java属性/调用java方法 (4)本地代码创建Java对象(包括javaString) (5) 本地方法处理java数组
- 我的处女贴: UITableView reloadData的正确方法。请每一个开发者必看。《转》
- 【iOS开发】UITableView 默认选择某行的方法
- UITableView设置单元格的高度的方法
- UI_UITableView省市区字典数组
- UITableView的自定义cell方法总结
- 防止数组越界处理
- UITableView SDK委托方法详解
- 解决tableview顶部留白一段的处理方法
- searchDisplayController 引起的数组越界处理办法