在UITableViewCell的“右侧详细信息”中显示信息

时间:2013-07-12 10:01:30

标签: uiviewcontroller uitableview

我有一个带有静态单元格的UITableViewController。每个单元格都有正确的细节风格。通过触摸其中一个,我转到下一个控制器。在下一个控制器中,我有两个带有复选标记的单元格。

问题:如何通过触摸NEXT控制器上的一个单元格,在“正确的细节”中查看信息?

1 个答案:

答案 0 :(得分:0)

根据上面的评论,我对你想要达到的目标有一个初步的想法。您想使用[cell setAccessoryView:aView];代替setAccessoryType

对应于您想要显示多少信息(如果它只是一个小图像或一个巨大的textView),有更好的选择。

我建议您创建一个自定义UITableViewCell子类。这些可以在IB中进行布局,您可以非常轻松地连接IBOutlets并在其上放置自定义方法和属性:

- (void)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MUTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell) {
        cell = (MUTableViewCell *)[[[NSBundle mainBundle] loadNibNamed:@"MUTableViewCell" owner:nil options:nil] objectAtIndex:0];
    }
    [cell setStoredInfoText:[inforSourceArray objectAtIndex:[indexPath row]]];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    MUTableViewCell *cell = (MUTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    [cell callYourCustomMethod];
    [cell setInfoFieldText:@"my informational text"];
    // or either display the information you set later to the cell in -cellForRowAtIndexPath
    [cell setInfoFieldText:[cell storedInfoText]];
    // you can also merge the above methods to a method called displayInfo which then gets the storedText property internally:
    [cell displayInfo];
}


MUTableViewCell.h
@property (nonatomic, retain) NSString *storedInfoText;
@property (nonatomic, strong) IBOutlet UILabel *label;
- (void)setInfoFieldText:(NSString *)text;
- (void)displayInfo;

MUTableViewCell.m
- (void)setInfoFieldText:(NSString *)text {
    [_label setText:text];
}
- (void)displayInfo {
    [_label setText:_storedInfoText];
}
相关问题