ios7 indexPathForCell 的坑(真是一个大大的坑)
2015-05-29 13:41
429 查看
笔者在编写APP 有一个功能点击cell上一个button,修改cell的在tableview中的位置
在ios8上没有问题。
在ios7上总是崩溃
以下是崩溃后提示:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (11) must be equal to the number of rows contained in that section before the update (11), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
开始怀疑是删除或插入indexpath 有问题 。google了下,解决方法各式各样。
后来断点调试发现在ios7上
[self.tableviewindexPathForCell:myCell] 返回了nil
在ios8中使用了
- (void)selecttop:(id)sender{
if ([sender isKindOfClass:[UIButtonclass]]) {
UIView *view = sender;
AppListCell *myCell = (AppListCell *)view.superview.superview;
NSIndexPath * cellPath = [self.tableviewindexPathForCell:myCell];
}
google下是ios7 上cell上面还多了一个UITableViewWrapperView 具体可以参见:/article/1829466.html
stackoverflaw 中 http://stackoverflow.com/questions/19282304/uitableview-indexpathforcell-ios6-v-ios7
有一个很好的处理方法
- (void)selecttop:(id)sender{
if ([sender isKindOfClass:[UIButtonclass]]) {
UIView *view = sender;
while (![view isKindOfClass:[UITableViewCellclass]]) {
view = [view superview];
}
AppListCell *myCell = (AppListCell *)view;
NSIndexPath * cellPath = [self.tableviewindexPathForCell:myCell];
}
标记下
真的是个坑!!!
据说ios6上也是两个superview 就可以获取到!!!!
在ios8上没有问题。
在ios7上总是崩溃
以下是崩溃后提示:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (11) must be equal to the number of rows contained in that section before the update (11), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
开始怀疑是删除或插入indexpath 有问题 。google了下,解决方法各式各样。
后来断点调试发现在ios7上
[self.tableviewindexPathForCell:myCell] 返回了nil
在ios8中使用了
- (void)selecttop:(id)sender{
if ([sender isKindOfClass:[UIButtonclass]]) {
UIView *view = sender;
AppListCell *myCell = (AppListCell *)view.superview.superview;
NSIndexPath * cellPath = [self.tableviewindexPathForCell:myCell];
}
google下是ios7 上cell上面还多了一个UITableViewWrapperView 具体可以参见:/article/1829466.html
stackoverflaw 中 http://stackoverflow.com/questions/19282304/uitableview-indexpathforcell-ios6-v-ios7
有一个很好的处理方法
- (void)selecttop:(id)sender{
if ([sender isKindOfClass:[UIButtonclass]]) {
UIView *view = sender;
while (![view isKindOfClass:[UITableViewCellclass]]) {
view = [view superview];
}
AppListCell *myCell = (AppListCell *)view;
NSIndexPath * cellPath = [self.tableviewindexPathForCell:myCell];
}
标记下
真的是个坑!!!
据说ios6上也是两个superview 就可以获取到!!!!
相关文章推荐
- IOS开发中的几种设计模式介绍
- FFmpeg在iOS上完美编译
- iOS webView中调用JS与JS注入
- iOS7 edgesForExtendedLayout
- Toncat-OpenSSL双向认证配置(iOS)
- xcode 运行错误总结
- iOS开发的22个奇谲巧技
- 仿制新浪微博iOS客户端之一-序言
- IOS开发入门初体验
- 数据存储:数据持久化
- 数据存储:获取文件目录
- ios8之后的CLLOCATION定位权限申请
- iOS:Compile error List(二)--Special
- 用CocoaPods做iOS程序的依赖管理
- 网易新闻iOS版使用的18个开源组件
- iOS手势
- iOS中keychain存储结构的研究
- IOS开发中tableView显示列表内容数据(storyboard版)
- ios各种动画效果
- [IOS 开发] 开发错误总结-警告篇