2010-02-12 23 views
0

我有一個tableview控制器。 如果選擇了小區i執行以下步驟:提交對象到下一個TableViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

ablogSingleCatTableViewController *singleCatTableViewController = [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain]; 

// Push the detail view controller. 
[[self navigationController] pushViewController:singleCatTableViewController animated:YES]; 
[singleCatTableViewController release]; 
} 

我要提交一個目的是選擇了該行之後的滑動在下一視圖控制器。 我必須做這樣的事嗎?

ablogSingleCatTableViewController *singleCatTableViewController = [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain]; 
[singleTableViewController setMyObject:superDuperObject]; 

還是有更簡單的方法來做類似的事情嗎? 我在這個tableviewcontroller被初始化後直接需要這個對象,用它來填充屬於這個對象的特定數據。

請給我一些建議。

感謝

回答

1

您也可以通過對象到下一個視圖控制器,當你初始化視圖控制器。
爲此,您需要爲視圖控制器實現您自己的初始化程序。
例如:

- (id)initWithStyle:(UITableViewStyle)style superDuper:(SuperDuper*)superDuperObject { 
    if (self = [super initWithStyle:style]) { 
     superDuper = superDuperObject; 
    } 
    return self; 
} 

然後,

ablogSingleCatTableViewController *singleCatTableViewController = 
    [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain superDuper:superDuperObject]; 
+0

是的,我想過,重寫initialize方法,謝謝。 – choise 2010-02-12 07:29:05