Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在UIView中放置UITableViewController以进行触摸开始在iPhone中工作?_Iphone_Uiview_Uinavigationcontroller_Uitableview_Touchesbegan - Fatal编程技术网

如何在UIView中放置UITableViewController以进行触摸开始在iPhone中工作?

如何在UIView中放置UITableViewController以进行触摸开始在iPhone中工作?,iphone,uiview,uinavigationcontroller,uitableview,touchesbegan,Iphone,Uiview,Uinavigationcontroller,Uitableview,Touchesbegan,我从另一个UITableViewController类(如表1)创建并显示一个UITableViewController(如表2)类,如下所示 -(void)createTable2 { Table2Controller *table2Controller = [ [Table2Controller alloc] initWithStyle:UITableViewStyleGrouped]; UINavigationController * nav = [[UINavigat

我从另一个UITableViewController类(如表1)创建并显示一个UITableViewController(如表2)类,如下所示

-(void)createTable2 {
     Table2Controller *table2Controller = [ [Table2Controller alloc] initWithStyle:UITableViewStyleGrouped];
     UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:table2Controller];
     [self.navigationController presentModalViewController:nav animated:YES];
     [nav release];
     [table2Controller release];
}
因此,将显示表2。我想使用touchesbeent方法在表2中退出键盘,因为我有一些UITextField作为单元格。我将UITextFieldDelegate协议包含在表2的.h文件中


但我知道这些touchesbeent方法只适用于UIView&而不适用于UIViewController(对吗?)。但是我不知道在哪里以及如何(我尝试了createTable2函数本身。它不起作用)添加一个UIView,然后在该UIView中添加Table2来完成事情。。。有什么建议吗

您的表视图控制器具有表视图属性。您可以对表视图进行子类化,然后重写方法,例如
-touchesbeated:withEvent:
。实例化自定义表视图并将此实例设置为view属性。

UIViewController控制屏幕上显示的UIView和其他UI元素。由于UIResponder类的存在,所有这些元素都可以响应触摸

使用Table2Controller覆盖touchesBegind方法来控制此viewController中任何UI元素上发生的触摸事件

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        [inputTV resignFirstResponder];
    [super touchesBegan:touches withEvent:event];
}

注意始终调用超级方法声明,以便您的触摸可以沿着响应链向上移动。

在单元格中添加UItextfield时,只需添加txt.delegate=self;然后覆盖UITextFieldDelegate方法。您可以使用-touchesBegind:withEvent:)抱歉,我忘了添加此项。我已经加了你的台词。但是它不获取调用哪个方法不被调用…UITextFieldDelegate方法或TouchBegan为什么不为此使用tableview委托?感谢您的详细回复。。我只是用上面的方法。实际上,我的Table2类有UITextField的UITextView。这会给调用touchesbeent方法带来任何问题吗?在线上有很多教程和示例:例如。,