gpt4 book ai didi

ios - 使用 UIActionSheetDelegate 执行多个 Segue

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:42 24 4
gpt4 key购买 nike

我希望通过单个 UIBarButtonItem 按钮进行多个 segue,并根据通过 UIActionSheetDelegate 的响应,正确的 UIViewController将通过 push segue 加载。这是我当前用于 UIActionSheetDelegate 的代码。

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// rate this app
}

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

else if (buttonIndex == 2)
{
[self performSegueWithIdentifier:@"featureRequestSegue" sender:self];
}
}

问题是我无法通过 Storyboard segues 将同一个按钮链接到多个 View 。我想知道是否有解决方法。

编辑

这就是我的代码现在的样子:(减去 Storyboard)

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// rate this app
}

else if (buttonIndex == 1)
{
[self.storyboard instantiateViewControllerWithIdentifier:@"bugReportIdentifier"];
}

else if (buttonIndex == 2)
{
[self.storyboard instantiateViewControllerWithIdentifier:@"featureRequestIdentifier"];
}
}

最佳答案

而不是使用 segueperformSegueWithIdentifier

考虑使用 StoryboardIDinstantiateViewControllerWithIdentifier:

为此,在 Storyboard 中,只需创建一个 View Controller 并且不要将任何 segues 连接到它。在属性检查器的第三个选项卡中,为其分配一个 Storyboard ID:

Example

然后,在您的代码中,您可以像这样创建一个实例:

[self.storyboard instantiateViewControllerWithIdentifier:@"ImagePicker"]

虽然每次都会创建一个新实例,因此您仍然应该保存它并尽可能重新使用它。

编辑:获得 View Controller 后,您需要自己呈现它。

如果您使用的是 NavigationViewController 调用:

UIViewController * newController = [self.storyboard instantiateViewControllerWithIdentifier:@"ImagePicker"];
[self.navigationController pushViewController:newController];

如果没有你可以使用:

UIViewController * newController = [self.storyboard instantiateViewControllerWithIdentifier:@"ImagePicker"];
[self presentViewController:newController animated:YES completion:nil];

编辑 2:您的最终代码应如下所示:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// rate this app
}

else if (buttonIndex == 1)
{
UIViewController * controller = [self.storyboard instantiateViewControllerWithIdentifier:@"bugReportIdentifier"];
[self presentViewController:controller animated:YES completion:nil];
}

else if (buttonIndex == 2)
{
UIViewController * controller = [self.storyboard instantiateViewControllerWithIdentifier:@"bugReportIdentifier"];
[self presentViewController:controller animated:YES completion:nil];
}
}

关于ios - 使用 UIActionSheetDelegate 执行多个 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24128201/

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