我有一個UITableView在我的UIView,有不同數量的部分,取決於一些條件。我收到下面的例外情況。NSInternalInconsistencyException表視圖中的錯誤節號?
終止應用程序由於未捕獲的異常 「NSInternalInconsistencyException」,理由是:「無效的更新:無效 節數。更新(1)後表 視圖中包含的部分數量必須等於更新(2)前表格視圖中包含的部分 的數量,加上或減去插入或刪除部分的 數目(1插入,0刪除)。
從錯誤,似乎我在數據源中有不同數量的部分? 如何解決問題?
這是我的接口:
@interface bookDetailView : SomeView <UITableViewDelegate,UITableViewDataSource>
{
UITableView *bookDetailTableView;
....
}
這是我的看法初始化
UIView *view = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame] autorelease];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.view = view;
UITableView *tableView = [[[UITableView alloc] initWithFrame:view.bounds style:UITableViewStyleGrouped] autorelease];
tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.delegate = self;
tableView.dataSource = self;
tableView.sectionIndexMinimumDisplayRowCount = 20;
bookDetailTableView = tableView;
[self.view addSubview:bookDetailTableView];
代碼崩潰在insertSections ....
if (![book method1])
{
[bookDetailTableView insertSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1,1)] withRowAnimation:UITableViewRowAnimationFade];
}
else
{
[bookDetailTableView insertSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2,1)] withRowAnimation:UITableViewRowAnimationFade];
}
numberOfSectionsInTableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (editMode)
{
if(newbookFlag || listBook)
{
return 1;
}
else
{
if(![book preferable])
{
return 2;
}
else
{
return 3;
}
}
}
}
任何想法?我嘗試了beginUpdates和endUpdates,問題仍然存在。
什麼值是「numberOfSectionsinTable」和「numberOfRowsinTableView」函數返回 – AppleDelegate
@AppleDelegate如何打印它?通過NSLog? – cateof
是的..通過NSLog ..你可以找到@你是什麼情況下得到異常..由@Niels回答你對該部分所做的修改應該反映到'numberOfSectionsInTableView:' – Nina