从其他视图或页面将值传递给自定义表

时间:2011-05-13 09:09:53

标签: iphone objective-c

我有自定义单元格(TJourneyListCell),我有一些标签,我想知道如何通过从其他视图中输入更多值来填充表格,我已经让用户输入他的名字和所有这种思考。他还输入了它应该显示在表中的值。我只是尝试这个硬代码值,但是当用户从其他视图输入值时我需要更多行ganrate。

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"Cell";
    TJourneyListCell *cell = (id)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[TJourneyListCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                        reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.namelbl.text =@"My journey";
    cell.distancelbl.text = @"raji";
    cell.infolbl.text = @"pradeep"; 
    cell.timelbl.text = @"harish";
    cell.userimageview.image = [UIImage imageNamed:@"listIcon-H.png"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
 }

2 个答案:

答案 0 :(得分:1)

创建一个存储数据的单独model object class

具有通用视图A和表视图B访问此模型类的实例的属性。

阅读Apple关于Model-View-Controller设计模式的文档。

答案 1 :(得分:0)

您应该通过委派将其他视图中的信息发送到tableViewController:

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW18

在你的delegateMethod中(类似于:userDidFinsihEnteringInformation :) 您可以在桌面上重新加载数据:

 - (void)reloadData

希望这有帮助, 文森特