我有兩個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