1

我有一个表格视图控制器,它有几行,每行前面都有一个按钮。一旦我单击一个按钮,与该按钮对应的数据就必须显示在另一个表视图控制器中。同时单击两个按钮时,新的表格视图控制器应该具有对应于两行的数据。

但是,我无法获得全部数据。只有最新的点击会反映在新的表格视图控制器中并打印一行。请帮助我。

谢谢

4

2 回答 2

0

为了实现这一点,您需要:

1) 声明属性 NSMuttableArray *rowData;

2)为每行按钮使用一个单击处理程序(将下面的代码添加到第一个 TableViewController)

- (void) viewDidLoad {
    [super viewDidLoad];

    [myButton addTarget:self action:@selector(rowButtonHandler:)forControlEvents:UIControlEventTouchUpInside];
}

- (void) rowButtonHandler:(id)button {
    if ([rowData count])
    {
        [self performSelector:@selector(openNewTableView) withObject:nil afterDelay:0.3];
    }

    [rowData addObject:...]; // add here row data
}

- (void) openNewTableView {
    SecondTableViewController* detailViewController = [[SecondTableViewController alloc] initWithNibName:@"SecondTableViewController" bundle:nil];

    // set collected rowDatas to SecondTableViewController

    [self.navigationController pushViewController:detailViewController animated:YES];

    [rowDatas removeAllObjects];
}
于 2012-09-26T13:48:11.350 回答
0

我认为您可以安排(以 300 毫秒的小延迟)调用在第一次单击按钮时显示“另一个表视图控制器”+ 在 NSMuttableArray 中添加值时单击某个按钮。当时间(300 毫秒)结束时,您将拥有 NSMuttableArray,其中包含需要在 UITableView 中显示的数据。

于 2012-09-26T12:48:11.357 回答