gpt4 book ai didi

iphone - UIAlertView 按钮到另一个 View Controller

转载 作者:行者123 更新时间:2023-11-28 19:09:06 25 4
gpt4 key购买 nike

我的应用程序中有一个 uialertview,它有两个按钮,第一个是取消按钮,第二个可以。当我按下确定按钮时,我想转到具有 Storyboard标识符“RootView”的 View Controller ,但它不起作用。我将此代码放在 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];


}
}

最佳答案

你想插入新的 View Controller 或以模态方式呈现它吗?假设最后一个,也许这对你有帮助:

RootView *viewController = [storyboard instantiateViewControllerWithIdentifier:@"RootView"];
UINavigationController *navigationController = [UINavigationController alloc] initWithRootViewController:viewController];
[self presentViewController:navigationController animated:YES completion:nil];

关于iphone - UIAlertView 按钮到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17447889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com