【问题标题】:Push notification in view based app?在基于视图的应用程序中推送通知?
【发布时间】:2011-12-12 15:48:59
【问题描述】:

我创建了一个基于视图的应用程序。在视图控制器类中,我动态创建了一个选项卡栏。该应用程序运行良好,但我在处理推送通知时遇到问题。虽然发送推送通知意味着我收到了推送警报,但我想知道如何显示标签栏的选定索引 3。

在基于视图的应用程序中,我在 2 类之后动态创建了这个标签栏。

tabbar1 = [[UITabBarController alloc] init];

    tab_obj1 = [[First alloc] initWithNibName:@"First" bundle:nil];

    UINavigationController *tabItem1 = [[[UINavigationController alloc] initWithRootViewController: tab_obj1] autorelease];
    tabItem1.title=@"First";
    tabItem1.tabBarItem.image=[UIImage imageNamed:@"FirstIcon.png"];
    tab_obj2 = [[Second alloc] initWithNibName:@"Second" bundle:nil];

    UINavigationController *tabItem2 = [[[UINavigationController alloc] initWithRootViewController: tab_obj2] autorelease];

    tabItem2.title=@"Second";
    tabItem2.tabBarItem.image=[UIImage imageNamed:@"SecondSelc.png"];

    tab_obj3 = [[Third alloc] initWithNibName:@"Third" bundle:nil];

    UINavigationController *tabItem3 = [[[UINavigationController alloc] initWithRootViewController: tab_obj3] autorelease];

    tabItem3.title=@"Third";
    tabItem3.tabBarItem.image=[UIImage imageNamed:@"ThirdIcon.png"];
    tab_obj4 = [[Fourth alloc] initWithNibName:@"Fourth" bundle:nil];

【问题讨论】:

  • 您能否提供代码示例/您尝试过的内容?
  • 我提供了一些代码来在基于视图的应用程序中创建动态标签栏。

标签: iphone objective-c push-notification


【解决方案1】:

在下面的方法中编写代码以选择标签栏索引

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo   {
    // Notification code here
}

每次收到通知时都会调用上述方法,因此您可以在此处编写代码以选择标签栏索引。

【讨论】:

  • 通知进入这个函数。从这里我检查了活动状态和非活动状态,我继续重定向特定选项卡。
【解决方案2】:

您的问题与推送通知无关...

要显示 TabBarController 的任何给定选项卡,您可以执行以下操作:

tabBarController.selectedIndex = 3;

其中tabBarController 是指向应用程序标签栏控制器对象的指针。

selectedIndex 更改为代表More 控制器的值需要特别注意。有关详细信息,请查看 UITabBarControllerselectedIndex 属性的文档。

【讨论】:

  • 感谢您的建议。但这适用于基于标签栏的应用程序。这里我使用基于视图的应用程序,因为我创建了动态标签栏控制器。所以我面临这个问题要处理。我在上面添加了一些代码。请参考并给出想法。提前致谢。\
  • 哦。我明白了...好吧,首先您将标签栏控制器的视图添加到主窗口,因此它完全可见。然后,我在回答中提出的建议将起作用。查看基于标签栏的应用程序的模板,了解如何将标签栏控制器的视图添加到主窗口。
【解决方案3】:

开发人员您好,
感谢您回复我。
我将在 tabBar 选项卡中显示该徽章值。 我在 didReceiveRemoteNotification 方法和非活动状态应用程序中再次创建 tabBar 控件

tabbarcontroller_obj.tabBarItem.badgeValue=@"3"

像这样我在应用程序内处理通知徽章值.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多