0

我的应用程序中有一个 uialertview,它有两个按钮,第一个是取消按钮,第二个是好的。当我按下“确定”按钮时,我想转到具有情节提要标识符“RootView”的视图控制器,但它不起作用。我把下面的代码放在 appdelegate.m 方法中。

- (void)showAlarm:(NSString *)text {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"show alarm"
                                                            message:text delegate:self
                                                  cancelButtonTitle:@"cancel"
                                                  otherButtonTitles:@"ok", nil];


        [alertView show];
    }

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

        if (buttonIndex == 0){
             NSLog(@"cancel"); 

        }else if (buttonIndex == 1){
             NSLog(@"ok");
           UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];


           UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"navigationController"];


            [navigationController presentViewController:[storyboard instantiateViewControllerWithIdentifier:@"RootView"] animated:YES completion:nil];


        }
    }
4

2 回答 2

3

你想推新的视图控制器吗?假设最后一个,也许这可以帮助你:

RootView *viewController = [storyboard instantiateViewControllerWithIdentifier:@"RootView"];
UINavigationController *navigationController = [UINavigationController alloc] initWithRootViewController:viewController];
[self presentViewController:navigationController animated:YES completion:nil];
于 2013-07-03T12:39:03.220 回答
1

请查看我的示例代码,它适用于我

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    [self showAlert];
    return YES;
}
-(void)showAlert
{
    UIAlertView *alertForCall = [[UIAlertView alloc]initWithTitle:@"" message:@"time to choose" delegate:self   cancelButtonTitle:@"YES" otherButtonTitles:@"NO", nil];
    [alertForCall show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
    {
        self.viewController = [[NewsTestViewController alloc] initWithNibName:@"NewsTestViewController" bundle:nil];
        UINavigationController *testNavi = [[UINavigationController alloc]initWithRootViewController:self.viewController];
        self.window.rootViewController = testNavi;
        [self.window makeKeyAndVisible];

    }
}
于 2013-07-03T12:39:39.267 回答