触摸appDelegate中的事件

时间:2013-04-17 10:04:44

标签: iphone ios uiview uigesturerecognizer appdelegate

这是我的问题。

我已经在我的应用中实现了推送通知,它运行正常。

  • 该应用会收到一条消息
  • 在appDelegates中捕获:didReceiveRemoteNotification
  • 创建一个新的UIView以显示收到新消息

我遇到的唯一问题是我希望用户能够点击消息,以便应用程序打开消息viewcontroller。但我似乎无法弄清楚如何捕捉这种触摸,然后在appDelegate中用它做一些事情。我在方法中有一个NSLog应该打开新的viewcontroller,但它似乎永远不会被调用。

任何帮助将不胜感激!

这是代码,它位于didReceiveRemoteNotification方法中:

    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoMessages)];
    UIView *messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
    messageView.userInteractionEnabled = YES;
    messageView.backgroundColor = [UIColor darkGrayColor];
    [messageView addGestureRecognizer:recognizer];
    [self.window addSubview:messageView];

谢谢!

1 个答案:

答案 0 :(得分:0)

我建议你不要使用你的app delegate类。这不是它的原因,它会导致设计混乱。

为什么不使用常规视图控制器和UIView子类?它们是手势和触摸输入的自然场所。

至于为什么你的NSLog没有出现,显示代码也可能会有所帮助。

您的点击手势识别器似乎配置为允许在屏幕上的任何位置点按任何点按,而不是像您提到的那样点按邮件右侧。仅供参考。