【问题标题】:iOS - segue from alert view is not being callediOS - 未调用警报视图中的 segue
【发布时间】:2014-05-13 16:56:14
【问题描述】:

当我按下 AlertView 上的“手动输入”和“扫描标签”按钮时,我想要执行一个 segue。

@implementation triageViewController
- (IBAction)addNew:(id)sender {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add A New Entry"
                                                message:@"Choose a way to add a new entry."
                                               delegate:nil
                                      cancelButtonTitle:@"Cancel"
                                      otherButtonTitles:@"Manual Entry", @"Scan Tag", nil];
  [alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  if (buttonIndex != alertView.firstOtherButtonIndex) {
    [self performSegueWithIdentifier:@"manual" sender: self];
}
  if (buttonIndex != alertView.cancelButtonIndex) {
    [self performSegueWithIdentifier:@"scan" sender: self];
  }
}

(我意识到这可能会使取消按钮现在成为一个 segue,但我更关心使其工作)

我的故事板中有两个 segue,从一个 UITabViewController 到两个不同的 UIViewController。这些都没有被调用,所以当我点击它们时。我尝试同时使用 push 和 modal segues,但都没有工作。

我也尝试过这样的 if/else 语句:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
    [self performSegueWithIdentifier:@"manual" sender: self];

}
if (buttonIndex == 1) {
    [self performSegueWithIdentifier:@"scan" sender: self];
}
}

但这也不起作用。

有人可以帮我找出问题所在吗?再次,如果我不清楚,我想从位于 UITabBarController 上的 UIAlertView 弹出窗口到两个单独的 UIViewControllers 执行 segue。 谢谢

【问题讨论】:

  • 什么不完全有效?您的代码是否通过了if 测试?
  • 在 clickedButtonAtIndex 中放置断点并调试它会发生什么?它会绕过 if 语句吗?还是它调用performSegue? segue 的命名是否正确,它们是否直接连接到 TriageViewController?想要发布故事板那部分的照片吗?
  • 大家好,segue 不起作用。我意识到我只是忘记将代表设置为self,正如@Miron 所回答的那样。谢谢

标签: ios objective-c uiviewcontroller uialertview uistoryboardsegue


【解决方案1】:

看起来你的UIAlertView 有一个delegatenil,所以你的函数永远不会被调用。将其设置为self,然后在您的视图控制器的标题中确保您正在实现UIAlertViewDelegate 协议。

【讨论】:

  • 该死,不知道为什么我没有注意到这一点,谢谢你让我头疼。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-01
  • 1970-01-01
  • 2011-02-05
  • 1970-01-01
相关资源
最近更新 更多