我想打开一个特定的视图,因为否则发出通知是没有意义的。 在stackoverflow上,大多数问题是关于选项卡式应用程序..但我有一个视图控制器。
这是我当地的通知:
UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = @"Test";
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
这是我为我的app delegate.m
找到的代码- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.mainVC = [[UIViewController alloc] initWithNibName:@"MyTestViewController" bundle:nil];
self.window.rootViewController = self.mainVC;
[self.window makeKeyAndVisible];
application.applicationIconBadgeNumber = 0;
return YES;
}
我尝试将其集成到我的应用中,但这是错误:在'AppDelegate'类型的对象上找不到属性'mainVC'。
我想打开'MyTestViewController'。有人可以向我解释我该怎么办?非常感谢你
答案 0 :(得分:0)
除非你在某个地方声明它,否则没有mainVC这样的东西。假设您想要设置一个MyTestViewController类的视图控制器,您可以这样做:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MyTestViewController *myTestVC = [MyTestViewController new];
self.window.rootViewController = myTestVC;
[self.window makeKeyAndVisible];
return YES;
}
如果您的应用是单一视图,您可以使用Xcode中的“单一视图应用程序”模板开始。
答案 1 :(得分:0)
导入
#import MyTestViewController.h
创建一个属性
@property(nonatomic, strong) MyTestViewController * myTestViewController;
和
self.myTestViewController = [[MyTestViewController alloc] initWithNibName:@"MyTestViewController" bundle:nil];
self.window.rootViewController = self.myTestViewController;
答案 2 :(得分:0)
试一试 - >
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
//present your controller here, for example
self.myTestViewController = [[UIViewController alloc] initWithNibName:@"MyTestViewController" bundle:nil];
[self.window.rootViewController pushViewController:self.myTestViewController animated:YES];
}