0

我正在制作一个表格对象,它通过滑动手势将显示的值更改为完全不同的值。这是有效的,因为有一个 UIPageControl 显示必须在表格上显示的集合。该代码涉及一个可变数组,该数组在页面的索引处包含可变数组。例如,第一页在索引 0 处给出了可变数组。包含的这些可变数组包含表格对象,并通过引用单元格的索引为表格提供适当的值。然而,发生的情况是,当表格包含超过 1 个单元格时,它会混合不同页面数组的对象,这是不应该发生的,因为这些是不同的数组。代码在这里:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    startDtLbl = [[UITextField alloc] initWithFrame:CGRectMake(10, 11, _answerTable.frame.size.width, 25)];
    startDtLbl.backgroundColor = [UIColor clearColor];
    startDtLbl.tag = 1;
    startDtLbl.returnKeyType = UIReturnKeyDone;
    startDtLbl.delegate = self
    [cell.contentView addSubview:startDtLbl];
}
else {
    startDtLbl = [cell.contentView viewWithTag:1];
}
startDtLbl.text = [[answers objectAtIndex:_pageView.currentPage] objectAtIndex:(indexPath.row)];
return cell; }

-(BOOL) textFieldShouldReturn:(UITextField *)textField {
UITableViewCell *textCell = [[textField superview] superview];
NSIndexPath *indexPathOfText = [_answerTable indexPathForCell:textCell];
[switchStates replaceObjectAtIndex:indexPathOfText.row withObject:textField.text];
[answers replaceObjectAtIndex:_pageView.currentPage withObject:switchStates];
[textField resignFirstResponder];
return YES; }

bool 方法只是将文本分配给数组,通过日志记录我发现这非常有效。另外,如果您没有注意到,单元格包含 TextFields。关于什么可能是错误的任何想法?

4

0 回答 0