liv*_*m95 5 iphone cocoa-touch
有没有办法隐藏UITableView单元格?我正在寻找一些我可以在同步cellForRowAtIndexPath()返回的UITableViewCell上调用的属性或方法来隐藏它并使用户无法选择它.
对我来说使用映射并不容易,所以我决定使用SAS方法.但它不适用于我的自定义单元格.所以,我纠正了它:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 7 && hide7Row){
UITableViewCell* cell = [cells objectAtIndex:indexPath.row];
cell.hidden = YES;
return 0.0;
}
else if(indexPath.row == 8 && hide8Row){
UITableViewCell* cell = [cells objectAtIndex:indexPath.row];
cell.hidden = YES;
return 0.0;
}
else {
return 44.0;
}
}
Run Code Online (Sandbox Code Playgroud)
工作良好.
你的意思是在表格中留下一个空格,或者只是从它之前的一个空格到它之后的一个空格?在前一种情况下,我猜你可能会尝试获取单元格contentView并将其hidden属性设置为YES; 否则,你就得做一点逻辑在你-tableView:numberOfRowsInSection:和-tableView:cellForRowAtIndexPath:方法,返回(否则你回细胞的数量- 1)从第一,并根据是否行指数比小于或大于你不包括的行(你要返回的单元格)或(单元格(行索引+ 1)).
(编辑,因为解释很复杂:)
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
if(section == theSectionWithoutARow)
{
if(shouldRemoveTheRow)
return [theArrayWithTheSectionContents count] - 1;
else
return [theArrayWithTheSectionContents count];
}
// other sections, whatever
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// blah blah standard table cell creation
id theCellObject;
if(indexPath.section == theSectionWithoutARow)
{
NSInteger theActualRowToDisplay = indexPath.row;
if(shouldRemoveTheRow && indexPath.row >= theRowIndexToRemove)
{
theActualRowToDisplay = indexPath.row + 1;
}
theCellObject = [theArrayWithTheSectionContents objectAtIndex:theActualRowToDisplay];
}
// now set up the cell with theCellObject
return cell;
}
Run Code Online (Sandbox Code Playgroud)