我有两个UITableViewController类,MainTableController和SubTableController。从一个表插入数据到另一个表
从AppDelegate类我打电话给MainTableController类。
起初这个类是空的,并且在这个类中有一个名为“show list”的按钮。 当我点击这个按钮时,我将进入SubTableController,在那里我有一个表格形式的动作列表。
现在,如果我选择第一个单元格操作,那么该操作名称必须位于MainTableController中的第一个表格单元格中。但是我无法在MainTableController类的表格中打印该名称。
在SubTableController:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ActionList * actionListObj = [appDelegate.actionArray objectAtIndex:indexPath.row];
self.chooseActions = actionListObj.actionName;
MainTableController * mainViewController = [[MainTableController alloc] init];
[mainViewController getAction:self.chooseActions];
[self.navigationController dismissModalViewControllerAnimated:YES];
}
在MainTableController:
-(void) viewWillAppear:(BOOL)animated{
[self reloadData];
}
-(void) reloadData{
[self.myTableView reloadData];
}
-(void) getAction: (NSString *) actionChoose{
self.action = actionChoose;
[self reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = self.action;
return cell;
}
当我调试,在MainTableController我得到的的getAction方法,但在表格单元格中的文本串的动作为空。
任何人都可以请帮我关于这个吗?我哪里错了?
文斯 - 它没有工作:(我想你说。但是我面对的这个问题是MainTableController不是委托类,它是一个tablViewController类。所以请给我一些更多的提示,请.. – hgpl 2012-02-08 10:28:46
我看不出任何理由为什么这是行不通的。不管什么类型的'mainViewController',你是否在推送时设置了子VC的属性? – 2012-02-08 10:32:27
是的,我做到了。我喜欢这个。在SubTableController.h文件中,MainActionViewController * mainViewController; @property(读写,分配)MainActionViewController * mainViewController;并在SubViewController.m中,[self.mainViewController getAction:self.chooseActions];在didSelectRowAtIndexPath:方法 – hgpl 2012-02-08 10:34:03