我创建了自定义单元格。当我在表格视图中使用这些自定义单元格时,我的单元格被替换了。我在表格视图中创建了约10个部分,其中每个部分包含1行。我为所有10个部分使用自定义单元格。当我滚动视图时,最后4个单元被顶部单元替换。我正在使用ReuseIdentifier,但它们仍在被替换。任何想法来解决这个问题?谢谢!自定义单元格被其他单元格替换
这是我的CustomCell代码!在的tableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
addCustomCell = [[CustomCellToAddDetailsController alloc] init];
switch (indexPath.section)
{
case 0:
cell = [addCustomCell returnCellForBirthdayDetails:tableView];
addCustomCell.customCellLabel.text = @"FirstName";
addCustomCell.customCellLabel.font = [UIFont boldSystemFontOfSize:12];
addCustomCell.customCellTextField.placeholder = @"FirstName";
[delegate.fieldArray addObject:addCustomCell];
break;
case 1:
cell = [addCustomCell returnCellForBirthdayDetails:tableView];
addCustomCell.customCellLabel.text = @"LastName";
addCustomCell.customCellLabel.font = [UIFont boldSystemFontOfSize:12];
addCustomCell.customCellTextField.placeholder = @"LastName";
[delegate.fieldArray addObject:addCustomCell];
break;
case 2:
cell = [addCustomCell returnCellForBirthdayDetails:tableView];
addCustomCell.customCellLabel.text = @"Dob";
addCustomCell.customCellLabel.font = [UIFont boldSystemFontOfSize:12];
addCustomCell.customCellTextField.placeholder = @"Dob";
addCustomCell.customCellTextField.inputView = dp;
addCustomCell.customCellTextField.inputAccessoryView=toolBarForTableView;
[delegate.fieldArray addObject:addCustomCell];
break;
case 3:
cell = [addCustomCell returnCellForBirthdayDetails:tableView];
addCustomCell.customCellLabel.text = @"Address";
addCustomCell.customCellLabel.font = [UIFont boldSystemFontOfSize:12];
addCustomCell.customCellTextField.placeholder = @"Enter Address";
[delegate.fieldArray addObject:addCustomCell];
break;
case 4:
cell = [addCustomCell returnCellForBirthdayDetails:tableView];
addCustomCell.customCellLabel.text = @"City";
addCustomCell.customCellLabel.font = [UIFont boldSystemFontOfSize:12];
addCustomCell.customCellTextField.placeholder = @"Enter City";
[delegate.fieldArray addObject:addCustomCell];
break;
case 5:
cell = [addCustomCell returnCellForBirthdayDetails:tableView];
addCustomCell.customCellLabel.text = @"State";
addCustomCell.customCellLabel.font = [UIFont boldSystemFontOfSize:12];
addCustomCell.customCellTextField.placeholder = @"Enter State";
[delegate.fieldArray addObject:addCustomCell];
break;
case 6:
cell = [addCustomCell returnCellForBirthdayDetails:tableView];
addCustomCell.customCellLabel.text = @"Email";
addCustomCell.customCellLabel.font = [UIFont boldSystemFontOfSize:12];
addCustomCell.customCellTextField.placeholder = @"Enter Email";
[delegate.fieldArray addObject:addCustomCell];
break;
case 7:
cell = [addCustomCell returnCellForBirthdayDetails:tableView];
addCustomCell.customCellLabel.text = @"Phone";
addCustomCell.customCellLabel.font = [UIFont boldSystemFontOfSize:12];
addCustomCell.customCellTextField.placeholder = @"Enter MobileNo";
[delegate.fieldArray addObject:addCustomCell];
break;
}
return cell;
[addCustomCell release];
}
-(UITableViewCell *)returnCellForBirthdayDetails:(UITableView *)tableView
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCellForBirthdayDetails"];
if(cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"CustomCellToAddDetails" owner:self options:nil];
cell = customCell;
// customCell = nil;
}
return cell;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[customCellTextField resignFirstResponder];
return YES;
}
- (UITextField *)textField
{
UITextField *textField = nil;
if(customCell)
{
textField = (UITextField *)[customCell.contentView viewWithTag:101];
}
return textField;
}
,并在这里,我呼吁定制单元请让我知道我在做什么错误。谢谢!!
给你的代码。 – Shubhank 2012-03-07 08:43:29
@kiran尝试附加一些代码的问题,它会很好..! – Kamarshad 2012-03-07 08:43:58
当然,我正在添加代码... – Kiran 2012-03-07 08:45:42