2011-02-25 64 views
0

我的应用程序是基于导航的。其中我有一个主要的tableView显示单元格中的feed项目。当单击单元格时,会创建一个detailview,其中显示该Feed项目的详细信息。我现在正在使用推送通知。当点击通知中的动作按钮时,iPhone:如何重新加载tableView并从AppDelegate推一个detailView?

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo: 

被调用。我如何实现该方法,如果通知中的操作按钮被点击。它应该再次解析Feed,重新加载tableview,创建最新的feed项目detailview并将其推送到导航堆栈中。我尝试了一些代码,但没有奏效。这是我写的代码。

中的AppDelegate:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
       RootViewController *controller = [[RootViewController alloc] init]; 
       [controller newFeedItem]; 
    } 

在RootViewController的:

- (void)newFeedItem 
    { 
     spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
spinner.frame=CGRectMake(130, 170, 50, 50); 
[self.view addSubview:spinner]; 
[spinner startAnimating]; 

[self performSelector:@selector(doStuff) withObject:nil afterDelay:0.01]; 
    } 

    -(void)doStuff 
    { 

    [[self stories] removeAllObjects]; 
    [self startParsing]; 
    [self.tableView reloadData]; 
// create detailview and push it in navigational stack 
     [spinner stopAnimating]; 
    [spinner release]; 
} 

,但活动的指标没有出现和的tableView也没有重装。为什么会这样呢?提前Thanx

回答

1

不太清楚您的程序流程,但我假设您在程序启动时显示rootViewController,并在稍后您收到远程通知。

在你的代码中(在didReceiveRemoteNotification),你正在实例化一个新的rootViewController,并且这个新的将与已经在屏幕上的那个不同。按照您的方法,您可能需要分配控制器一次,并在远程通知到达时保留它。

我个人建议使用本地通知并在didReceiveRemoteNotification中触发本地通知并在rootViewController中捕获它。这将确保当前活动的控制器实例响应。

也不知道为什么微调不显示,试图从viewDidAppear调用它,只是它看到它可以工作,如果问题是与远程通知的反应。并使用一些断点。


编辑针对您的评论:

在接口

定义

RootViewController *controller

在执行你的Alloc控制器(例如在appDidFininshLaunching

if (controller == nil) controller = [[RootViewController alloc] init] 

didReceiveRemoteNotification然后你可以做

  [controller newFeedItem]; 

没有再次分配它,你可以参考相同的控制器。不要忘记释放它在-(void)dealloc

+0

好,如果我不会实例化一个新的rootViewController,我将再次解析饲料。所有解析都发生在rootViewController中。是否有可能在didReceiveRemoteNotification中写入一些代码来访问我已有的rootViewController? – Piscean 2011-02-25 14:14:47

+0

是我在程序启动时显示rootViewController,稍后我收到远程通知。并且我希望在点击通知中的操作按钮时重新加载tableView。 – Piscean 2011-02-25 14:18:30

+0

请查看我对如何重用控制器的回答的编辑 – Olaf 2011-02-25 14:42:53

相关问题