gpt4 book ai didi

ios - 如何将父 View Controller 设置为对象,以便我可以调用它的方法之一?

转载 作者:行者123 更新时间:2023-11-29 03:57:31 25 4
gpt4 key购买 nike

我需要向父 View Controller 发送数据;所以(在父级中)我创建了一个方法 setLocWithName: loc: 来执行此操作。如何创建一个作为父 Controller 的对象?我尝试了 parentViewController 以及 presentingViewController (如下所示),但我收到警告:

使用“UIViewController *”类型的表达式初始化“TDViewController *__strong”时不兼容的指针类型

// set object of parent view controller
TDViewController *tDViewController = [[self navigationController] presentingViewController];

// get data
NSArray *locs = [[PLStore sharedStore] allLocs];
PL *setselectedLoc = [locs objectAtIndex:[indexpath row]];

// send data to parent view controller
[tDViewController setLocWithName:[setselectedLoc pLocName] loc:[setselectedLoc loc1]];

// Pop this view controller off the stack
[self.navigationController popViewControllerAnimated:YES];

最佳答案

假设presentingViewController(或parentViewController?)实际上是TDViewController类型,你只需要在第一行进行强制转换:

TDViewController *tDViewController = (TDViewController *)[[self navigationController] presentingViewController];

关于ios - 如何将父 View Controller 设置为对象,以便我可以调用它的方法之一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16327385/

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