我想單擊展開UITableViewCell。嘗試展開UITableView單元時聲明失敗
我之前在應用程序中完成了這項工作,使用與現在使用的步驟相同的步驟,但我想我正在監督某些內容,但我無法弄清楚它是什麼。
我想顯示一些頭條新聞,存儲在一個可變數組
NSMutableArray* topicsArray;
_topicsArray = [[NSMutableArray alloc]init];
[_topicsArray addObject:@"Percent"];
[_topicsArray addObject:@"Decimal numbers and fractions"];
[_topicsArray addObject:@"Variables and expressions"];
[_topicsArray addObject:@"Geometry - Area and perimeter"];
[_topicsArray addObject:@"Mathematics in use"];
[_topicsArray addObject:@"Reduction of expression"];
[_topicsArray addObject:@"Chance and probability"];
[_topicsArray addObject:@"Academic reading - Find century"];
這是我使用擴大/縮小細胞上點擊代碼:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.topicsArray containsObject:indexPath])
{
[self.topicsArray removeObject:indexPath];
}
else
{
[self.topicsArray addObject:indexPath];
}
[_tableView beginUpdates];
[_tableView endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat kExpandedCellHeight = 210;
CGFloat kNormalCellHeigh = 80;
if ([self.topicsArray containsObject:indexPath])
{
return kExpandedCellHeight;
}
else
{
return kNormalCellHeigh;
}
}
當我做了我的自定義單元格,我選擇了「清除圖形內容」和「剪輯子視圖」。
單擊單元格時發生錯誤。的代碼,其中山雀發生 線是
[_tableView endUpdates];
在
- (無效)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath方法。
此外,消息我得到的是:
終止應用程序由於未捕獲的異常 「NSInternalInconsistencyException」,理由是:「無效的更新:包含在第0行的數目無效 行數 更新後的現有部分(9)必須等於該部分所包含的行數 更新前(8),加號或減號 插入或刪除該行的行數(0插入, 0刪除)並加上或減去移入或移出的行數 該部分(0移入,0移出)。'
問題的根源是什麼?