【发布时间】:2015-09-24 02:55:23
【问题描述】:
在我的项目中,我有两个 ViewController——mapViewController 和 dataViewController。
在 mapViewController 中,我有两个按钮的插座:
@property (weak, nonatomic) IBOutlet UIButton *previousButton;
@property (weak, nonatomic) IBOutlet UIButton *nextButton;
用于在dataViewController中获取mapViewController,
self.MapViewController = ((OTPAppDelegate *)[[UIApplication sharedApplication] delegate]).mapViewController;
使用上面的技术,我可以通过访问self.MapViewController.property来操作dataViewController内部mapViewController的属性
但是,如果我希望使用以下代码为 dataViewController 中的两个按钮添加目标:
[self.MapViewController.previousButton addTarget:self action:@selector(doNothing:) forControlEvents:UIControlEventTouchDown];
它会引发 BAD 访问错误。我想知道需要修复什么,以实现所需的按钮点击行为。
【问题讨论】:
-
你创建了mapview控制器的对象吗?
-
@Bhumika:我想是的。否则,操作其他属性应该不起作用,对吧?
-
使用 nsnotificationcenter 或委托方法在另一个视图控制器中调用操作
标签: ios objective-c uiviewcontroller uibutton