我在我的應用程序中有一個uialertview,有兩個按鈕,第一個是取消按鈕,第二個是好的。當我按下OK按鈕時,我想要轉到具有故事板標識符「RootView」的視圖控制器,但它不起作用。 我把下面的代碼放在appdelegate.m方法中。UIAlertView按鈕到另一個視圖控制器
- (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];
}
}
是否日誌打印出「OK」或不? – Venkat
是的,它打印,它的工作原理,但導航到另一個視圖控制器的操作不起作用 – CarinaM