我试图在不使用 segue 的情况下导航到场景。我使用的代码如下所示:
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
MyViewController * controller = (MyViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
[self presentViewController:controller animated:YES completion:nil];
我的问题是为这个场景设置委托(delegate)。通常我会做以下事情:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Check the segue identifier
if ([[segue identifier] isEqualToString:@"showDetail"])
{
[[segue destinationViewController] setDelegate:self];
}
}
但我不想使用转场。谁能告诉我如何为场景设置代理?
谢谢
最佳答案
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DetailViewController * controller = (DetailViewController *)[storyboard instantiateViewControllerWithIdentifier:@"DetailView"];
controller.delegate = self;
[self presentViewController:controller animated:YES completion:nil];
关于iOS,在不使用 segue 的情况下为场景设置委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15289606/