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

标签 ios objective-c ios6 parentviewcontroller presentviewcontroller

我需要向父 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/

相关文章:

ios - Swift UITableView didSelectRowAtIndexPath 错误

iphone - 如何在 iPhone 上自动发布推特?

iphone - EKEventEditor 在 iPhone 上崩溃,但在 iPad 上没有

iphone - 使用ios 4创建的应用在ios 6中崩溃且未安装

android - 使用 Qt5 为 iOS 和 Android 创建应用程序

iphone - 为 UILabel 赋值时模拟器崩溃

ios - 在 UIButton 中显示图像

ios - 环绕 UIView 的一些角并环绕 View 层的边框

ios - 组 TableView 背景颜色在 ios 6.0 中已弃用

ios - 发布旋转 UIImage