【发布时间】:2012-08-08 02:52:37
【问题描述】:
我的TableViewController 中有ageTextField 属性。我将它添加到第一部分单元格的 subciew 中,但我不知道为什么当我向下滚动时它会显示在另一部分 (#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 的占位符是如何在Section3,cell3..中复制的。
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
这很奇怪,我不知道发生了什么!请帮忙..
【问题讨论】: