gpt4 book ai didi

ios - 当文本字段在 uitableview 的单元格中时,不调用 touchesBegan

转载 作者:行者123 更新时间:2023-12-01 18:12:22 25 4
gpt4 key购买 nike

所以我有一个文本字段,我在 .h 文件中有 UITextFieldDelegate。
我在 .m 文件中声明文本字段:

UITextField * titletextfield

我将文本字段放在表格 View 的一个单元格中。我将文本字段委托(delegate)设置为自我,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==0) {
static NSString *CellIdentifier = @"Title";
UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel * label;
if (cell == nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
label = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, 90.0, cell.frame.size.height)];
label.text =@"sth :";
label.font=[UIFont systemFontOfSize:14.0];
label.textColor =[UIColor grayColor];

titletextfield =[[UITextField alloc]initWithFrame:CGRectMake(100, 0, cell.frame.size.width-100.0, cell.frame.size.height)];
self.titletextfield.delegate=self;

UIView *message = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, cell.frame.size.width, cell.frame.size.height)];
message.tag = 0;
message.backgroundColor =[UIColor clearColor];
[message addSubview:label];
[message addSubview:titletextfield];
[cell.contentView addSubview:message];
}
return cell;}

touch begin 从未被调用:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"123");
[self.view endEditing:YES];
[super touchesBegan:touches withEvent:event];
NSLog(@"22");

}

当我取消选中从 tableview 启用的用户交互时,开始调用 touchbegan 函数。但是,在这个 cad 中,我不能再将焦点放在文本字段上。
以前有人有同样的问题吗?谢谢!

最佳答案

这里发生的事情意味着当您启用 UITableview“用户交互启用”属性时,UITableview 的 ScrollView 会观察到所有的触摸。此时 UITableview 的 ScrollView 的所有 subview 都会获取触摸事件(在这种情况下,您的 uitextfield 也是)。所以viewcontroller 的 View 的 touchesBegan 方法永远不会调用。如果禁用 UITableview 的“用户交互启用”属性,则 UITableview 的 ScrollView 不会观察到所有触摸事件并提供给 viewcontroller 的 View 。此时将调用 touchesBegan。

关于ios - 当文本字段在 uitableview 的单元格中时,不调用 touchesBegan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28022105/

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