2011-06-01 52 views
2

我有UITableView作爲我的rootViewController,我用解析的RSS填充該表(其中有Parser類,其中我的rootViewController是其代表)。在rootViewController我有耳目一新RSS refreshData方法和我保持我的retreived數據在靜態MutableArray staticItems:打開接收推送通知的具體視圖

在點擊tableView細胞的detailView被踩下navigationController細胞,而在同一時間(在選擇單元格(row))我創建並將字典theItem傳遞給detailView。在該字典中,我傳遞了staticItemspositionInArray(選定單元格的索引)的值。通過這種方式,我可以顯示新聞文本並跟蹤新聞陣列中新聞的位置,以實現幻燈片上一頁/下一頁。

現在,我啓用了推送通知,並且在接收到一個應用程序時,我的應用程序回到了前臺,但是應用程序關閉時上次打開的視圖已關閉。

我想通過重新解析(刷新)RSS並顯示上一條消息(theItem [0])來顯示detailView的最新消息

所以,我想有結果如下:調用[rootController refreshData],然後選擇第一項在細胞開放它detailView

我一直在玩的委託方法didReceiveRemoteNotification,但我無法找到使其工作的方式。我試圖創造新的rootController,但後來我將其疊在現有:(。

請分享你與我的想法:)

+0

@ViTo兄弟Apoyan:我的問題被編輯(刪除嗨,最後感謝),現在我的斜體不再是斜體。我格式錯了嗎?日Thnx – luigi7up 2011-06-02 13:49:27

回答

3

首先,這個問題是不是真的有關在所有推送通知。這更多的是如何從應用程序委託中的任意位置訪問視圖控制器的問題。

你最好的(也可能是唯一的)賭注是手動保持對相關視圖控制器實例的引用。

我假設你使用UINavigationController,其中根是你的列表,然後你將一個詳細視圖控制器推到它上面。在應用程序委託中保留對此導航控制器的引用。將@property (nonatomic, retain) UINavigationController *mainNavController;添加到您的應用程序委託。當您創建導航控制器時,將其分配,以便應用程序委託具有引用。

MyAppDelegate *ad = ((MyAppDelegate *)[UIApplication sharedApplication].delegate); 
ad.mainNavController = theNavController; 

如果創建的應用程序代理本身的導航控制器,你明明只需要做到這一點:

self.mainNavController = theNavController; 

然後,當你收到一個推送通知,只需直接作用於導航控制器上。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    // Do whatever you need to do in order to create an instance of your 
    // detail view controller 
    MyDetailViewController *vc = [MyDetailViewController magicalStuff:userInfo]; 

    // Add the detail view controller to the stack, but keep the root view 
    // controller. 
    UIViewController *root = self.mainNavController.topViewController; 
    NSArray *vcs = [NSArray arrayWithObjects:root, vc, nil]; 
    [self.mainNavController setViewControllers:vcs animated:YES]; 
} 

而且,導航控制器將要設置動畫MyDetailViewController與刷卡和後退按鈕將帶你到列表中。