Ios 具有不同单元格的自定义tableview
我是iOS新手。我有一个表格视图,我想在其中加载不同的自定义单元格 这是我的代码,来自Ios 具有不同单元格的自定义tableview,ios,tableview,custom-cell,Ios,Tableview,Custom Cell,我是iOS新手。我有一个表格视图,我想在其中加载不同的自定义单元格 这是我的代码,来自tableViewCellForRowAtIndexPath: if (self.mainTableView .tag==SEARCH) { static NSString *cellId=@"Cella"; CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cell
tableViewCellForRowAtIndexPath
:
if (self.mainTableView .tag==SEARCH)
{
static NSString *cellId=@"Cella";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
NSArray *topLevelOjects= [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell=[topLevelOjects objectAtIndex:0];
}
//code goes here
return cell;
}
else
{
static NSString *mCell = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mCell];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
}
//code goes here
return cell;
}
在方法nnumberofrowsinsecutions:(UITableView*)tableview
中,我有:
if (tableView.tag==SEARCH)
{
return [firstList count];
}
else
{
return [secondList count];
}
我遇到的问题是,每次执行ELSE时,tableview都包含第一个和第二个CustomCell。为什么?我终于找到了问题所在。else分支上使用的标识符实际上是CustomCell*cell=.的标识符。。(如有分支机构)。没有Cella标识符:)。此代码在哪里实现?在
表格视图中:cellForRowAtIndexPath:
?在tableView:numberofrowsin部分:
?我建议将if(self.mainTableView.tag==SEARCH)
更改为if(tableView.tag==SEARCH)
。那么何时放置标签?如果单元格的高度不同,您还必须实现heightforrowatinexpath:
,否则它们将重叠。我已更新了我的问题。谢谢你细胞的大小不一样