簡體   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