我有動態創建的自定義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 - 不只是例外:)
只要是clarea,哪一個是'UITextView'或'UITextField',這些都是不同的東西 – danypata
還有一件事,如果用戶點擊單元格的任何位置,你想選擇UITextView/UITextField? – danypata
@ danypata - 遺憾的是,在所有情況下都應該讀取UITextField - 直接編輯它。我想在用戶點擊時選擇UITextField - 而不是整個單元格 - 我只是不能解決爲什麼滾動屏幕外並再次返回導致它不能正常工作 – SimonTheDiver