我創建了自定義單元格。當我在表格視圖中使用這些自定義單元格時,我的單元格被替換了。我在表格視圖中創建了約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