ios7 indexPathForCell 的坑(真是一個大大的坑)

來源:互聯網
上載者:User

標籤:

筆者在編寫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 具體可以參見:http://blog.csdn.net/u013604612/article/details/23120615

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 就可以擷取到!!!!

 

ios7 indexPathForCell 的坑(真是一個大大的坑)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.