如何检查我当前的navigationController.view是否=aclasses.view?原因=推送通知。 + iPhone

发布于 2024-09-17 21:37:36 字数 655 浏览 2 评论 0原文

所以基本上在我的应用程序委托中我有一个 navigation.controller

这个导航控制器有一个名为 MainScreen 的类的视图。

在 MainScreen.m 中,我有一个 IBAction,通过推动它会将我带到 SelectionScreen.m 页面。这是它的编码

SelectionScreen *aSelectionScreenViewController = [[SelectionScreen alloc]initWithNibName:@"SelectionScreen" bundle:nil];
[self.navigationController pushViewController:aSelectionScreenViewController animated:YES];
[aSelectionScreenViewController release];

那么我如何检查我当前的navigationController.view =这个selectionscreen.view?

检查它是哪个当前视图的原因是因为当我收到推送通知时,我想自动切换到此 SelectionScreen.m 页面并调用其中的一些方法。但此检查只能在 appDelegate 中完成,因为 didReceiveRemoteNotification 方法位于其中。

so basically in my app delegate i have a navigation.controller

This navigation controller has a view of a class named MainScreen.

In MainScreen.m , i have a IBAction which will bring me to a SelectionScreen.m page by pushing it. here is the coding for it

SelectionScreen *aSelectionScreenViewController = [[SelectionScreen alloc]initWithNibName:@"SelectionScreen" bundle:nil];
[self.navigationController pushViewController:aSelectionScreenViewController animated:YES];
[aSelectionScreenViewController release];

So how do i check if my current navigationController.view = this selectionscreen.view?

The reason for checking which current view it is, is because when i receieve a push notification, i would want to automatically switch to this SelectionScreen.m page and invoke some methods within it. But this checking can only be done in the appDelegate because the didReceiveRemoteNotification method is located in there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

君勿笑 2024-09-24 21:37:36

这就是我的做法,

例如,如果您有三个 ViewController,并且其中任何一个都有可能由 NavigationController 推送:

ViewControllerA
ViewControllerB
ViewControllerC

那么您需要做的是:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ([[self.navigationController topViewController] isKindOfClass:[ViewControllerA class]]) {

    //do sth
    }

    if ([[self.navigationController topViewController] isKindOfClass:[ViewControllerB class]]) {

    //do sth
    }

    if ([[self.navigationController topViewController] isKindOfClass:[ViewControllerC class]]) {

    //do sth
    }

}//end of code

This is how i'm doing it

for example if you have three ViewControllers ,and any of those have possibility to be pushed by NavigationController:

ViewControllerA
ViewControllerB
ViewControllerC

Then what you need to do is:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ([[self.navigationController topViewController] isKindOfClass:[ViewControllerA class]]) {

    //do sth
    }

    if ([[self.navigationController topViewController] isKindOfClass:[ViewControllerB class]]) {

    //do sth
    }

    if ([[self.navigationController topViewController] isKindOfClass:[ViewControllerC class]]) {

    //do sth
    }

}//end of code
最舍不得你 2024-09-24 21:37:36

一种方法是将 SelectionScreenViewController 保存为应用程序委托的属性,然后:

if (self.navigationController.topViewController == self.selectionScreenViewController) {
   //...
}
else {
   //...
}

One way is to save selectionScreenViewController as a property of your app delegate, then:

if (self.navigationController.topViewController == self.selectionScreenViewController) {
   //...
}
else {
   //...
}
栖迟 2024-09-24 21:37:36

嘿伙计们,我用一种简单的方式做到了。在我拥有的每个视图控制器中,我删除了所有对象并将一个对象分配给应用程序委托中的数组。这样,每次我进入一个新视图时,值都是不同的。

因此,在 appdidrecieveremotenotification 中,我可以检查该数组并决定相应的操作。

这只是一种简单的检查方法。

Hey guys, i did it in a simple way. In every view controller i had, i removed all objects and assigned an object to an array in the appdelegate. So this way, everytime i go to a new view, the value is different.

So in appdidrecieveremotenotification, i can check that array and decide on what to do accordingly.

Its just a simple way of checking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文