在一个页面中只有一个UITableView,用一个SegmentedControl来控制显示两个list。其中一个list只想让它显示标题,另外一个则带有备注。之前总是两个list都只能显示标题,后来发现种方法,主要思想是为两种cell使用不同的identifier,记录下来以备后用,顺便也明白了identifier是干这个用的。
在(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法中做就可以了。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableViewIndex==0)
{
static NSString *personTableIdentifier=@"personTableIdentifier";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:personTableIdentifier];
if(cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:personTableIdentifier];
}
NSInteger row=[indexPath row];
cell.textLabel.text=[account.relativePerson objectAtIndex:row];
return cell;
}
else
{
static NSString *itemTableIdentifier=@"itemTableIdentifier";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:itemTableIdentifier];
if(cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:itemTableIdentifier];
}
NSInteger row=[indexPath row];
cell.textLabel.text=[[account.items objectAtIndex:row]toNSString];
cell.detailTextLabel.text=[[account.items objectAtIndex:row]description];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
}