繁体   English   中英

具有文本字段的uitableview中的滚动问题

[英]Scrolling issue in uitableview having textfields

我有一个包含多个部分的UItableview ,每个部分都有包含标签和文本字段的两行。 滚动数据时,文本字段会更改其位置。

[1]: UITableView滚动问题这个问题与我的问题类似,但我无法获得确切的解决方案。

这是我的数据源,即cellForAtIndexPath方法。

static NSString *CellIdentifier = @"Cell";

UILabel *   mainLabel;    
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];        
    cell.accessoryType = UITableViewCellAccessoryNone;        
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(20.0, 8.0, 100.0, 30.0)] autorelease];
    mainLabel.tag = MAINLABEL_TAG;
    mainLabel.font = [UIFont systemFontOfSize:17.0];
    mainLabel.textColor = [UIColor blackColor];
    mainLabel.backgroundColor = [UIColor clearColor];
    [cell.contentView addSubview:mainLabel];
    mainTF = [[[UITextField alloc]initWithFrame:CGRectMake(150, 8.0, 140.0, 30)] autorelease];
    mainTF.tag = MAINTEXTFIELD_TAG;
    mainTF.font = [UIFont systemFontOfSize:17.0];
    mainTF.textColor = [UIColor blackColor];
    mainTF.backgroundColor = [UIColor clearColor];
    mainTF.borderStyle = UITextBorderStyleRoundedRect;
    mainTF.delegate = self;
    mainTF.autocorrectionType = UITextAutocorrectionTypeNo;
    mainTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    mainTF.returnKeyType = UIReturnKeyDone;
    mainTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    mainTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [cell.contentView addSubview:mainTF];
}
else{
    mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
    mainTF = (UITextField *)[cell.contentView viewWithTag:MAINTEXTFIELD_TAG];
}

if (indexPath.row == 0) {
    mainLabel.text = @"Quantity";
    //mainTF.text =@"1";
}
else{
    mainLabel.text = @"Unit";
    //mainTF.text = @"100 grams";
}

// Configure the cell...
return cell;
}

如果您将单元出队,则它们将包含先前放入其中的数据。 您应该在每次加载单元格时将textfield.text初始化为@“”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM