0

I have multiple table views that display different items. The detail view for each cell though should have the same layout. I want to use the same detail view for all the cells of each table without having to implement a different detail view class for each table since it'll pretty much be the same code. How do I do this?

The following method is in one of the table views. This displays the detail view when a cell is selected:

-(void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"didSelectRowAtIndexPath");
    AppDelegate *delegate =
        (AppDelegate *)[[UIApplication sharedApplication] delegate];

    Detail *detail=
        [[Detail alloc] initWithIndexPath:indexPath];

    [delegate.navController pushViewController:detail animated:YES];

    [tv deselectRowAtIndexPath:indexPath animated:YES];
}

The following is the viewDidLoad method in the Detail view class:

- (void)viewDidLoad
{
    [super viewDidLoad];

    AppDelegate *delegate =
    (AppDelegate *)[[UIApplication sharedApplication] delegate];

    PokemonInfo *thisPokemon = [delegate.allArray objectAtIndex:index.row];
    self.title = thisPokemon.name;

    nameView.text = thisPokemon.name;
    typeView.text = thisPokemon.type;
    attackView.text = thisPokemon.attack;
    attackView.editable = NO;
}
4

1 回答 1

0

创建视图并将其布置在笔尖中。在视图中给每个元素一个唯一的标签。当您需要使用 nib (UINib) 实例化视图时,然后在您想通过使用“viewWithTag”询问来填充它时访问每个元素。假设您正在回收单元格,您总是使用适当的数据设置任意视图的元素。

如上所述,更传统的方法是在 nib 中实例化一个单元格,然后执行相同操作 - 您要访问的每个元素都有一个唯一的标签。

于 2012-08-07T18:39:27.067 回答