在UITableViewDataSource
方法,我检查,看看是否我有数据:DeqeueReusableCellWithIdentifier重叠两个小区
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
if (data.count == 0)
{
return 1; //This one cell will be of type NoDataTypeCell
} else {
return data.count //These cells will be of type DataTypeCell
}
}
在
cellForRowAtIndexPath
所以检查要使用哪种类型的细胞,以同样的方式:
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
SAFindSuggestedTableViewCell* dataCell = (SAFindSuggestedTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"hasDataIdentifier" forIndexPath:indexPath];
if (data.count == 0)
{
NODataTypeCell* cellNoData = (NODataTypeCell*)[tableView dequeueReusableCellWithIdentifier:@"noDataIdentifier];
//Setup the noDataCell
return cellNoData;
} else {
return dataCell;
}
}
这会导致我从未见过的东西。正如所料,我的控制器加载的数据是空的。结果,1个NODataTypeCell被出队。
数据进来后,TableView被重新加载。
numberOfRowsInSection
回报data.count
cellForRowAtIndexPath
不返回noDataCell
,它返回data.count
量dataCells
除了我的tableView仍然有noDataCell。最奇怪的部分?它直接在tableView的第一个单元格上。单元格是不可选的,并且使单元格不可选。它没有数据,因为它尚未设置。但它在那里,它不会消失。
我在做什么错?
这里是单元格后面的视图调试器透视图。你可以清楚地看到,有两个单元的第一行,只有一个在第二行单元格
您是否尝试将SAFindSuggestedTableViewCell的出列转移到else子句?因为即使你没有返回要呈现的dataCell,看起来好像出列进程并没有处理好更好的出列。 – CStreel
@CStreel这是当我按照你的建议时抛出的错误:由于未捕获的异常'NSInvalidArgumentException',原因:' - [_ UITableViewReorderingSupport _needsSetup]:无法识别的选择器发送到实例0x148b4b6d0' – YichenBman