我想要一些幫助,因爲我想找到一個好的方法來發佈一個NSMutableArray到另一個類。發送NSMutableArray到一個UIViewController
所以我有一個NSMutableArray一個UIViewController
例如(如果用戶選擇從RootViewController的一個細胞,其是推動)
代碼在RootViewController的當用戶選擇一個小區:
QueryTableViewController *queryTableView
= [[QueryTableViewController alloc] initWithQuery:query];
[self.navigationController pushViewController:queryTableView animated:YES];
[queryTableView release];
代碼在QueryTableViewController
@interface QueryTableViewController : UIViewController{
NSMutableArray *results;
}
@implementation QueryTableViewController // more code
-(int)fetchQueryWithString:(NSString*)string{
// Searching twitter.
// add objects in the results array.
// **HERE** Once I gather all the objects I am posting a notification:
}
在另一側我有DetailViewController裏面是空的,並且需要在陣列創建另一個的UIViewController和添加子視圖。 例如
// when the notification is received
self.statsTableView = [[StatsTableVC alloc] initWithTweets:**HERE**];
[self addSubView:self.statsTableView];
目前我在fetchQueryWithString方法結束旨意通知共享陣列。我想知道是否有更好的方法將它發送到另一個UIViewController?
(我敢肯定有;)
在此先感謝。
感謝您的信息。將detailViewController設置爲單例並設置數組會是不好的選擇嗎? – PatrickG4
是的,沒有理由讓任何控制器成爲單身人士。控制器始終根據其特定的視圖和數據模型進行定製。因此,使一個人成爲一個單身人士是毫無意義的。控制器在Apple API採用的Model-View-Controller設計中不包含任何重要數據。他們應該簡單地引用一個數據模型對象,該對象可以是簡單數組,自定義對象或(最重要的)核心數據堆棧中的任何數據模型對象。 – TechZen
我創建了一個Repository對象作爲單例以在單獨的控制器上使用該數組。再次感謝。 – PatrickG4