0

我的应用是基于导航的。其中我有一个主 tableView,它显示单元格中的提要项目。单击单元格时,会创建一个详细视图,其中显示该提要项目的详细信息。我现在正在处理推送通知。单击通知中的操作按钮时,

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

叫做。如果单击通知中的操作按钮,我如何实现该方法。它应该再次解析提要,重新加载表格视图,创建最新的提要项目详细视图并将其推送到导航堆栈中。我尝试了一些代码,但没有用。这是我写的代码。

在 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 也没有重新加载。为什么会这样?提前感谢

4

1 回答 1

1

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

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

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

也不确定为什么微调器不显示,尝试从 调用它viewDidAppear,只是它看到它完全有效,如果问题出在对远程通知的反应。并使用一些断点。


针对您的评论进行编辑:

在界面定义

RootViewController *controller

在实现中你分配控制器(例如在appDidFininshLaunching

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

didReceiveRemoteNotification然后你可以做

           [controller newFeedItem];

无需再次分配它,您就可以引用同一个控制器。不要忘记释放它-(void)dealloc

于 2011-02-25T14:09:08.010 回答