[英]Custom tableview with different cell
I am new to iOS. 我是iOS新手。 I have a table view where i want to load different custom cells. 我有一个表格视图,我想在其中加载不同的自定义单元格。
Here is my code from tableViewCellForRowAtIndexPath
: 这是我来自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;
}
In method n umberOfRowsInSections:(UITableView *) tableview
I have: 在方法n umberOfRowsInSections:(UITableView *) tableview
我有:
if (tableView.tag==SEARCH)
{
return [firstList count];
}
else
{
return [secondList count];
}
The problem i have is that every time ELSE is executed the tableview contains both the first and second CustomCell. 我的问题是每次执行ELSE时,tableview都包含第一个和第二个CustomCell。 WHY? 为什么?
I finally found the issue. 我终于找到了问题。 The identifier used on else branch was actually the identifier used for the CustomCell *cell =.. (if branch). else分支上使用的标识符实际上是CustomCell * cell = ..(如果分支)使用的标识符。 There was no Cella identifier:). 没有Cella标识符:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.