iOS:如何在UITabBar中选择特定选项卡以及此选项卡中的特定行

时间:2014-04-03 07:03:18

标签: ios objective-c uitableview uitabbarcontroller appdelegate

我正在使用推送通知创建应用程序。我在AppDelegate中处理此通知(如果我已使用- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {已启用应用程序),如果我想通过推送通知启动我的应用程序我应该使用

UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if (notification)
{
    //Some code
}

如果应用收到一些新消息,我的推送通知会被调用。在"Some code"部分,我想在我的标签栏中打开特定标签(默认情况下TabBarController.selectedIndex设置为3)。我希望打开第一个选项卡并打开新添加的最后一条新闻(选项卡1是带有一些行的UITableView)。

我该怎么办?我真的不知道该怎么做。提前致谢。

1 个答案:

答案 0 :(得分:1)

在AppDelagate DidReceiveRemoteNotification

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    [tabBarController setSelectedIndex:0];

    YourTab1ViewController *tab1Controller = (YourTab1ViewController *)tabBarController.selectedViewController;

    [tab1Controller reloadYourTableViewWithNewData];
}

您的Tab1ViewController必须包含reloadYourTableViewWithNewData方法。此方法必须获取新数据并重新加载您的tableview。