gpt4 book ai didi

ios - 在 Segue 中但在 ViewDidLoad 中设置属性返回 null

转载 作者:行者123 更新时间:2023-11-29 01:39:14 25 4
gpt4 key购买 nike

好吧,这真让我头疼。我有 ViewController(使用替换),我分配了它的委托(delegate)属性

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"spoSelectionDemoPlanSegue"])
{
SPOSelectionViewController * vc = [segue destinationViewController];
vc.delegate = self;
NSLog(@"spo segue %@", vc.delegate); //returns current ViewController
}
}

SPOSelectionViewController.h

@property (nonatomic, assign) id<SPOInputDelegate> delegate;

SPOSelectionViewController.m

- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"delegate didload spo %@", delegate); //returns (null)
}

它以某种方式打印 null!但是,还有我的其他 ViewController(使用弹出窗口),我尝试分配它的委托(delegate),但它不是 null。谁能给我建议?

最佳答案

正如我所料,这很愚蠢,因为 Storyboard 的转场是导航 Controller ,所以实际上destinationViewController是导航 Controller 而不是SPOSelectionViewController

于是我就这样解决了:

UINavigationController* navController = segue.destinationViewController;
SPOSelectionViewController * vc = (SPOSelectionViewController*)navController.topViewController;
vc.delegate = self;

关于ios - 在 Segue 中但在 ViewDidLoad 中设置属性返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32611109/

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