我有一个主要的 UIViewController
,大部分用户的交互都发生在其中。在主 ViewController 中有三个 subview 。用户可以将单独的 ViewController 加载到 UIView subview 中。
每个加载的 subview 都处理数据输入。依次调用 firstResponders
。我希望能够通过主 ViewController 关闭 firstRespnders
,也许使用“完成”按钮。
我想我可以在每个单独的 subview 中添加一个方法,名称为 ex;
-(void) methodToResignResponders {}
然后,在主 ViewController 中将此方法调用到当前对用户打开的 View 。依次辞职在 subview 中处于事件状态的响应者。
更多信息:
这就是我将每个 View 设置为主 ViewController 的 subview 的方式:
UIViewController *calcVC;
//set up the view to be added depending on the name of the view that was passed
if ([viewName isEqualToString:@"Tax"]) {
calcVC= [[TAXViewController alloc]initWithNibName:@"TAXViewController" bundle:nil];
}else if ([viewName isEqualToString:@"Rent"]){
calcVC= [[RENTViewController alloc]initWithNibName:@"RENTViewController" bundle:nil];
}else //continues with more views...
//Then add it to the subview
[firstView addSubview:calcVC.view];
最佳答案
不确定我是否理解了这个问题的要点,主要是因为听起来您已经自己解决了这个问题。 :)
但是,据我所知,您所说的 ViewController 始终是一个名为 calcVC 的 UIViewController 实例。如果您引用的始终是此 viewController 的 View ,您可以简单地调用 [calcVC.view resignFirstResponder];
关于iphone - 调用存在于多个类中的方法的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14651150/