UITableViewCell上的UITextField停止响应触摸 - 可能由滚动屏幕外导致
我有动态创建的自定义UITableViewCells上的UITextFields。我正在使用它们来输入数据(如果它是一个编辑,则将它从核心数据中提取出来)并将数据写回到editingDidEnd上。UITableViewCell上的UITextField停止响应触摸 - 可能由滚动屏幕外导致
我的问题是我可以选择我的心脏内容的UITextFields,但如果他们滚动屏幕并再次回来我不能触摸UITextField。
如果没有数据并且textField中有数据,则会发生这种情况。当单元格滚动时,数据仍然存在。
有趣的是,如果我触摸文本框,造就了键盘,滚动池脱屏幕上,滚动回上,然后按下键盘上的回车键,我可以再次选择单元格。所以当UITextfield是FirstResponder时,滚动单元格似乎可以保护它免受我在这里做错的任何事情的影响。
投掷编码的几行,我已经决定了我触摸触发didSelectRowAtIndexPath方法时,它不是对细胞接触的UITextField。
我用故事板,我的出现使用cellIdentifiers
是正确有没有人经历过这种行为,并有一个建议,以我应该在哪里寻找?
任何建议将赞赏,因为在这一点上我已经花了近3天敲我的头撞在墙上试图找出什么在
要谢谢你。
danypata继承人的cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ 的NSString * CellIdentifier;
if (indexPath.section == dLocation){
[email protected]"FacilityAddressCell";
}else {
[email protected]"FacilityGPSCell";
}
DLog(@"****CellIdentifier = %@",CellIdentifier);
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
switch (indexPath.section) {
case dLocation:
{
FacilityAddressCell *theFacilityAddressCell = (FacilityAddressCell*) cell;
theFacilityAddressCell.facilityAddressField.placeholder = self.locationFieldNames[indexPath.row];
theFacilityAddressCell.accessoryType =UITableViewCellAccessoryNone;
theFacilityAddressCell.selectionStyle = UITableViewCellSelectionStyleNone;
switch (indexPath.row) {
case facilityName:
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.name;
break;
case webSiteUrl:
DLog(@"self.cur.website = '%@'",self.currentOperation.website);
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.website;
break;
case emailAddress:
DLog(@"self.cur.email = '%@'",self.currentOperation.email);
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.email;
break;
case country:
DLog(@"self.cur.country = '%@'",self.currentOperation.country);
theFacilityAddressCell.facilityAddressField.enabled = NO;
theFacilityAddressCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.country;
break;
case streetName:
DLog(@"self.cur.address = '%@'",self.currentOperation.address);
DLog(@"streetnames initial value is '%@'",self.currentOperation.address);
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.address;
break;
case areaName:
DLog(@"self.cur.address2 = '%@'",self.currentOperation.address2);
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.address2;
break;
case island:
DLog(@"self.cur.address3 = '%@'",self.currentOperation.address3);
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.address3;
break;
case postCode:
DLog(@"self.cur.postcode ='%@'",self.currentOperation.postcode);
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.postcode;
break;
case phoneNumber:
DLog(@"self.cur.phone ='%@'",self.currentOperation.phoneNumber);
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.phoneNumber;
break;
case faxNumber:
DLog(@"self.cur.fax ='%@'",self.currentOperation.faxNumber);
theFacilityAddressCell.facilityAddressField.text = self.currentOperation.faxNumber;
break;
case tapToBringForward:
theFacilityAddressCell.facilityAddressField.enabled=NO;
theFacilityAddressCell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
theFacilityAddressCell.facilityAddressField.text [email protected]"Use last location details";
break;
default:
break;
}
cell= theFacilityAddressCell;
}
break;
case dGPSLoc:
{
DLog(@"loading the [cell data");
GPSLocCell *theGPSLocCell = (GPSLocCell *)cell;
theGPSLocCell.latLabel.text= [self.currentOperation.latitude stringValue];
theGPSLocCell.longLabel.text=[self.currentOperation.longitude stringValue];
theGPSLocCell.lockedOrNotLabel.text = @"Locked";
cell= theGPSLocCell;
}
break;
}
return cell;
}
解决方案 - 但问题是,我重复使用电池和他们夫妇有textfield.enabled设置为NO,他们都拿到没有作为起始值重复使用。卫生署。希望我的愚蠢可以帮助其他人走出困境。当你重用UITableViewCell或其子类时,它们会保留先前使用的设置,并且如果某些具有相同重用类型的单元格的格式不同,最好确保将它们全部设置为cellForIndexPath - 不只是例外:)
有在你的交换机的几个地方,你设置
theFacilityAddressCell.facilityAddressField.enabled = NO;
因为细胞被重用,如果你在一个地方禁用的UITextField,你需要将其设置回在其他情况下启用。
尝试在indexPath.row上的开关上方添加此行。
theFacilityAddressCell.facilityAddressField.enabled = YES;
这就解释了为什么它在你开始滚动之前工作。如果你滚动一下,你的一些文本字段可能仍然有效,但如果你最终保持滚动上下滚动,它们都将被禁用。
非常感谢。这就是它。我只是写了一条日志语句来检查字段语句中的启用值,当你的建议通过时,停在那里,只需要启用= NO行,并且它在目前为止的有限测试中工作正常。我希望3天前我会问 - 有时你不能看到树木,需要另一只眼睛 – SimonTheDiver
,我认为你应该检查你的tableView:cellForRowAtIndex:和保证的UITableViewCell和它的子视图每个方法被调用时正确创建。
只要是clarea,哪一个是'UITextView'或'UITextField',这些都是不同的东西 – danypata
还有一件事,如果用户点击单元格的任何位置,你想选择UITextView/UITextField? – danypata
@ danypata - 遗憾的是,在所有情况下都应该读取UITextField - 直接编辑它。我想在用户点击时选择UITextField - 而不是整个单元格 - 我只是不能解决为什么滚动屏幕外并再次返回导致它不能正常工作 – SimonTheDiver