4

私のアプリでは、アラーム機能を使用しています。正常に動作しています。右ボタンをクリックすると、アプリが起動します。しかし、rootViewControllerではないViewControllerを起動したいと思います。GoogleとSOで検索してみましたが、アイデアや例が見つかりませんでした。

これを達成するための例を探しています。

助けてくれてありがとう。

編集

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{     
// Add the view controller's view to the window and display.
[self.window addSubview:alarmViewController.view];
[self.window makeKeyAndVisible];

application.applicationIconBadgeNumber = 0;


// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
    NSLog(@"Recieved Notification %@",localNotif);

    window = [[UIApplication sharedApplication] keyWindow];
    UIViewController *rootViewController = [window rootViewController];
    [rootViewController presentModalViewController:receipeViewController animated:YES];         
}


// Override point for customization after application launch.
return YES;

}

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notificaton when the app is running
NSLog(@"Recieved Notification %@",notif);   
//Called here as well
window = [[UIApplication sharedApplication] keyWindow];
    UIViewController *rootViewController = [window rootViewController];
    [rootViewController presentModalViewController:receipeViewController animated:YES];   
}
4

4 に答える 4

6

最後に、これが私がそれをした方法です。

didFinishLaunchingWithOptionsの場合:

//save the root view controller
[[self window] makeKeyAndVisible];
UINavigationController *navigationController = (UINavigationController*) self.window.rootViewController;
rootController = [[navigationController viewControllers] objectAtIndex:0];

アプリデリゲートの別の場所:

[rootController performSegueWithIdentifier:@"destinationSegue" sender:self];

次に、ストーリーボードで、「rootController」に割り当てられたビューから目的のオプションのビューにセグエを作成し、その新しいセグエにIDdestinationSegueを指定します。rootController変数が正しいビューに割り当てられるようにするには、デバッグが必要です。

于 2012-09-04T10:36:39.980 に答える
3

セグエを作成する必要はありません。ストーリーボードでViewControllerのIDを割り当てるだけです。

    [[self window] makeKeyAndVisible];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    LensOverviewViewController *editLensViewController = [storyboard instantiateViewControllerWithIdentifier:@"lensOverView"];
    UINavigationController *yourViewController = [[UINavigationController alloc] initWithRootViewController:editLensViewController];
    [self.window.rootViewController presentViewController:yourViewController animated:NO completion:nil];

通常[[セルフウィンドウ]makeKeyAndVisible]; didFinishLaunchingWithOptions関数には存在しませんが、rootviewcontrollerを表示するには明示的に呼び出す必要があります。

于 2014-04-23T22:21:37.797 に答える
1
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIViewcontroller *rootViewController = [window rootViewController];
[rootViewController presentModalViewController:alarmViewController animated:YES];
于 2012-08-14T15:11:53.783 に答える
0

アプリケーションが起動したら、次のメソッドのlaunchOptionsディクショナリでUIApplicationLaunchOptionsLocalNotificationKeyを探します。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

これにより、ローカル通知(アラームに使用する通知)が原因でアプリケーションが起動されているかどうかが通知されます。

次の場合にも同様のことができます。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

実際に通知を受信したと判断したら、ウィンドウからルートView Controllerを見つけて、モーダルで表示するViewControllerを提示します。

于 2012-08-14T15:20:20.407 に答える