【问题标题】:open a uiviewcontroller from uialertview button从 uialertview 按钮打开一个 uiviewcontroller
【发布时间】:2012-03-03 04:36:53
【问题描述】:

如果按下 UIALertView 按钮,我想打开一个 UIViewController。

我有那个代码。但是,没有打开 uiviewcontroller :(

我确信 uialertview 工作正常。 uiviewcontroller 的代码也很好。 (从其他地方调用时有效)。

有什么帮助吗?

谢谢。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) //Yes, Sign Me Up!
{
    NSLog(@"0");
    ViewerWebController *web = [[ViewerWebController alloc] initWithURL:[NSURL URLWithString:@"http://www.funimation.com/"]];
    [web setShowToolbar:YES];
    [self.navigationController pushViewController:web animated:YES];
    [web release];

}
else if (buttonIndex == 1) //Remove from List
{
    NSLog(@"1");
    [[NSUserDefaults standardUserDefaults] setBool:false forKey:@"subscribeButtonOption"];
    [_tableView reloadData];
}
else if (buttonIndex == 2) //"Maybe Later" 
{
    NSLog(@"2");
}
}

【问题讨论】:

  • 显然某些部分无法正常工作:) 请发布代码。
  • 您是将视图控制器推到导航控制器上还是模态显示视图控制器?
  • 你用什么来“打开” UIViewController?不看一些代码 sn-ps 很难说哪里出了问题。
  • 你能检查一下导航控制器是否在你尝试推送的时候初始化了吗? NSLog(@"%@",self.navigationController);

标签: objective-c ios uiviewcontroller uiwebview uialertview


【解决方案1】:

警报视图没有导航控制器。您需要保留对要将视图控制器推送到的导航控制器的引用。

【讨论】:

  • 我该怎么做?有什么提示吗?
  • 在您对 pushViewController 的调用正上方添加 NSLog(@" nav controller is %@", self.navigationController);。
【解决方案2】:

这可能有效..

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  // the user clicked one of the OK/Cancel buttons
  if (buttonIndex == 0)
  {
      YourRootNavigationController *navController = [YourRootNavigationController sharedInstance]; // singleton
      [navController pushViewController:YOUR_CONTROLLER animated:YES];
  }
  else
  {
    NSLog(@"cancel");
  }
}

【讨论】:

  • 我希望视图控制器成为导航控制器堆栈的一部分。这不可能吗?
【解决方案3】:

使用didDismissWithButtonIndex 而不是clickedButtonAtIndex。

前者在 UIAlertView 从屏幕层次结构中移除后调用,而后者在UIAlertView 仍在屏幕上 时发生。在屏幕上,UIAlertView 改变了应用程序的性质;这意味着尝试将视图推送到导航控制器时会发生不好的事情。

clickedButtonAtIndex 的这种滥用似乎是互联网和 StackOverflow 上常见的错误信息。让我沮丧了好几个小时。

【讨论】:

    猜你喜欢
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    相关资源
    最近更新 更多