にageTextField
財産がありますTableViewController
。最初のセクションセルのサブビューに追加しましたが、下にスクロールすると別のセクション (#3) に表示される理由がわかりません..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
// Configure the cell...
switch (indexPath.section){
case 0:
{
[cell addSubview:self.ageTextField];
}
break;
case 1:
{
cell.textLabel.text = [screeningArray objectAtIndex:indexPath.row];
if (indexPath.row == 0) //no choice
cell.accessoryType = self.doneScreening ? UITableViewCellAccessoryNone:UITableViewCellAccessoryCheckmark;
else //yes choice
cell.accessoryType = self.doneScreening ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
}
break;
case 2:
{
cell.textLabel.text = @"1 : ";
[cell addSubview:self.riskTextField];
}
break;
case 3:
{
cell.textLabel.text = [findingsArray objectAtIndex:indexPath.row];
cell.accessoryType = [[boolValuesArray objectAtIndex:indexPath.row] boolValue] ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
}
break;
default:
break;
}
cell.textLabel.font = [UIFont systemFontOfSize:14];
return cell;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
if (textField == self.ageTextField)
return (newLength > 2) ? NO : YES;
else
return (newLength > 7) ? NO : YES;
}
これが冒頭のスクリーンショットです..
http://dl.dropbox.com/u/30838210/Screen%20Shot%202012-08-07%20at%209.26.47%20PM.png
下にスクロールした後、ageTextField のプレースホルダーがセクション 3、セル 3 で複製されていることに注目してください。
http://dl.dropbox.com/u/30838210/Screen%20Shot%202012-08-07%20at%209.27.28%20PM.png
もう一度上にスクロールすると、section3 の cell3 のテキストが最初のセルに表示されます。
dl.dropbox.com/u/30838210/Screen%20Shot%202012-08-07%20at%209.27.52%20PM.png
それは奇妙で、何が起こったのか理解できませんでした! 助けてください..