【问题标题】:UIAlertView button to display viewControllerUIAlertView 按钮显示 viewController
【发布时间】:2013-01-21 11:48:20
【问题描述】:

我一直在互联网上寻找解决此问题的方法,但尚未找到我能理解的方法。就这样吧。 我有我的 iOS 应用程序,在第一次启动应用程序时,它会显示一个 UIAlertView。我想要其中一个按钮将用户发送到新的 viewController 以查看一些基本信息。

我的 UIAlertView 配置正确,下面是 actionSheet 的代码:

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{

//Code to open a new viewController???


}

if (buttonIndex == 1)
{

//User can exit the application if they do not wish to continue

exit(0);    }

}
}

我创建了一个名为 webViewViewController 的 viewController,这就是我希望用户在点击第一个按钮时访问的内容。关于如何做到这一点的任何想法?我禁用了 ARC,我遇到的其他“解决方案”不断给我错误。

谢谢大家,希望得到一些指导。

【问题讨论】:

  • 首先,exit(0):永远不会!提示:stackoverflow.com/questions/14335848/… 然后,要实例化一个新的 UIViewController,Apple Doc 应该很有用。
  • 我是个坏孩子,我会改变的。你能帮我吗?
  • 要显示警报视图,您必须先启动 rootView..
  • 我有一个 UIAlertView,请阅读我的问题
  • 我的理解是你有屏幕 A 和 B 。您在屏幕视图上有警报视图。如果您单击其中一个按钮,那么它应该进入 B 。对吗?

标签: objective-c button uialertview viewcontroller


【解决方案1】:

如果您当前的视图控制器在导航控制器中:

UIViewController *myViewController = [[UIViewController alloc] init];
myViewController.title = @"My First View";
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];

永远不要使用 exit(0)!

【讨论】:

  • 能不能做成模态视图控制器?
【解决方案2】:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{

 NewViewController *controller=[[NewViewController alloc]initWithNibName:@"NewViewController" bundle:nil];
            self.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
            [self presentViewController:controller animated:YES completion:nil];



}           

drasick 已经给出了足够的答案,但是如果您需要使用模型视图控制器,请参考上面。

【讨论】:

  • 接收“未知接收者”和“未知类型名称”,我的视图控制器名称是 webviewviewcontroller,有什么想法吗?
  • 在 .h 文件中的 #import 上转发声明类 @class className 并在 .m 中执行 #import 以避免循环依赖
【解决方案3】:

用途:

UIViewController *yourViewController = [[UIViewController alloc] init];
[self.navigationController presentModalViewController:myViewController animated:YES];

推送一个modalViewController。(这在iOS 6中被贬低了,但会起作用)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-28
    • 1970-01-01
    相关资源
    最近更新 更多