【发布时间】:2013-08-19 23:22:14
【问题描述】:
我知道这将是一个简单的解决方案,但由于某种原因,当我尝试使用其他解决方案解决我的问题时,它只是不起作用。在我的应用程序中,我设置了推送通知,并尝试设置从通知打开应用程序时将应用程序打开到某个 tabBarItem 的功能。这是我到目前为止的代码,请告诉我我是否使用了正确的方法。我对AppDelegate.m 不是很有经验,所以如果完全错误,请原谅我。
AppDelegate.m
#import <CoreLocation/CoreLocation.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate,CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}
@property (strong, nonatomic) UIWindow *window;
@property(nonatomic,readonly) UITabBar *tabBar;
@property(nonatomic,strong) UITabBarController *tabBarController;
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
return YES;
}
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo{
/* this works just fine*/
NSLog(@"opening from a notification!!");
/*this is what doesnt work at all*/
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController ];
self.tabBarController.selectedIndex = 3;
/*also when i do nslog the selectedIndex it gives me this value "2147483647"*/
NSLog(@"%i is the tabbar item",tabBarController.selectedIndex);
}
【问题讨论】:
-
你在哪里将它设置为 rootview 控制器?
标签: ios objective-c uitabbarcontroller appdelegate