我有一个tableview有四个部分,所有部分有两个文本框和一个标签在不同的行中。我添加了一些文本作为文本框的占位符。最初数据显示正常,但当我滚动tableview时,单元格开始有重叠的数据。
我的代码:uitableviewcell的数据在滚动上相互重叠
- (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] autorelease];
}
if(indexPath.row==0) {
UITextField *txtName = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, 300, 30)];
txtName.placeholder = @"Full Name";
[cell.contentView addSubview:txtName];
[txtName release];
}
else if(indexPath.row==1) {
UITextField *txtEmail = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, 300, 30)];
txtEmail.placeholder = @"Email";
[cell.contentView addSubview:txtEmail];
[txtEmail release];
}
else if(indexPath.row==2){
cell.textLabel.text = @"Select Date of Birth";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell...
return cell;
}
在此先感谢
潘卡
+1,但如果你在一个行设置accessoryType你应该在其他行禁用它。 – 2011-04-30 17:10:29
嗨贾森,谢谢你的回复,但textlabel文本出现在第0行也滚动几次。 – pankaj 2011-04-30 17:58:39
你想让它隐藏在第0行,并在其他地方可见吗? – 2011-04-30 18:02:16