動的に作成されたカスタム UITableViewCells に UITextFields があります。私はそれらを使用してデータを入力し(または編集の場合はコアデータから取得し)、editingDidEnd でデータを書き戻します。
私の問題は、UITextFields を心ゆくまで選択できることですが、画面をスクロールして再びオンにすると、UITextField に触れることができません。
これは、データがない場合と、textField にデータがある場合の両方で発生します。セルがスクロールして戻ったとき、データはまだそこにあります。
興味深いことに、textField に触れてキーボードを表示し、セルを画面外にスクロールし、スクロールして元に戻し、キーボードのリターン キーを押すと、セルを再度選択できます。したがって、UITextfield が theFirstResponder である間にセルをスクロールすると、ここで間違ったことからセルを保護しているようです。
数行のコーディングを行って、セルの UITextField に触れていないときに、私のタッチが didSelectRowATIndexPath をトリガーしていると判断しました。
ストーリーボードを使用していますが、cellIdentifiers を正しく使用しているようです
誰かがこの種の行動を経験したことがあり、私がどこを見るべきかについて提案がありますか?
この時点で、何が起こっているのかを理解しようとして、頭を壁にぶつけて3日近く費やしたので、どんな提案もいただければ幸いです。
ありがとうございました。
danypata は cellForRowAtIndexPath です
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ NSString *CellIdentifier;
if (indexPath.section == dLocation){
CellIdentifier=@"FacilityAddressCell";
}else {
CellIdentifier=@"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 =@"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 に設定されていて、 NO を開始値として再利用されていたことです。どー。私の愚かさがどこかで他の誰かを助けることを願っています.
教訓 - UITableViewCell またはそのサブクラスを再利用すると、以前の使用からの設定が保持されます。同じ再利用タイプの特定のセルが異なる形式でフォーマットされている場合は、例外だけでなく、 cellForIndexPath でそれらすべてを設定していることを確認してください。 :)