我正在使用Xcode 4.3.2
我实施了Local Notifications
,在预定时间提醒用户注意新事件。因此,当我的应用程序在后台并且时钟到达早上8点时(例如),用户将从我的应用程序收到通知。
当用户决定从后台查看应用时,我加载了一个笔尖。目前,这个笔尖正常工作:它显示了视图,因为它是在笔尖中排列的。但是,在向用户显示笔尖之后,我想将用户转发到LocalNotificationsHandler.m
中的其他视图。当我尝试推送第二个视图时,我的应用程序失败了。因此,虽然没有错误消息,但似乎第二个笔尖不会加载。
简而言之,流程如下:
LocalNotificationsHandler nib
将加载self.navigationController == nil
(在LocalNotificationsHandler.m中)我想知道我的AppDelegate.m文件中是否有我遗漏的东西所以我已经包含了 我的AppDelegate.m文件中的“didFinishLaunchingWithOptions”:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
NSLog(@"did finish launching with options");
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
if (self.locationManager == nil)
{
locationManager = [[CLLocationManager alloc] init];
locationManager.purpose = @"We will try to use you location";
}
if([CLLocationManager locationServicesEnabled])
{
[self.locationManager startUpdatingLocation];
}
self.navigationController.navigationBar.tintColor = nil;
return YES;
}
答案 0 :(得分:1)
您正在使用过时的(自iOS 3开始)方法将viewcontroller的视图添加到主UIWindow。那应该是这样的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// create properly sized window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// create instance of root VC and assign to window
MainViewController *vc = [[MainViewController alloc] init];
self.window.rootViewController = vc;
[vc release];
[self.window makeKeyAndVisible];
return YES;
}
如果视图控制器的navigationController属性实际上是从UINavigationController呈现的,则它是唯一设置的。
有关详细信息,请参阅此文章:http://www.cocoanetics.com/2012/11/revisited/