У меня одна проблема с двумя разделами в сгруппированном стиле UITableview. Первая секция имеет 6 рядов, а вторая секция имеет 3 ряда. Когда я прокручиваю вид таблицы вверх и вниз, содержимое последней строки раздела 2 добавляется в первый раздел первой строки, а содержимое первой строки первого раздела добавляется в последнюю строку второго раздела. Я лучше проверяю свой уровень, становится ли ячейка пустой для загрузки контента, но во время отладки этого не происходит. Мой код
- (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];
cell.backgroundColor = [UIColor whiteColor];
if (indexPath.section == 0 && indexPath.row == 0)
{
UILabel *Nameabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 140, 30)];
Nameabel.text = @"Name";
Nameabel.font = [UIFont fontWithName:@"Helvetica" size:15];
Nameabel.backgroundColor = [UIColor clearColor];
Nameabel.font = [UIFont boldSystemFontOfSize:15];
[cell.contentView addSubview:Nameabel];
textField = [[UITextField alloc] initWithFrame:CGRectMake(145, 5, 150, 30)];
textField.placeholder = @"Student Name";
textField.borderStyle = UITextBorderStyleNone;
textField.font = [UIFont fontWithName:@"Helvetica" size:14];
[cell.contentView addSubview:paymentCatTextField];
}
else if (indexPath.section == 1 && indexPath.row == 0)
{
UILabel *RLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 140, 30)];
RLabel.text = @"Class";
RLabel.backgroundColor = [UIColor clearColor];
RLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
RLabel.font = [UIFont boldSystemFontOfSize:15];
[cell.contentView RLabel];
RTextField = [[UITextField alloc] initWithFrame:CGRectMake(145, 5, 150, 30)];
RTextField.placeholder = @"class Name";
RTextField.borderStyle = UITextBorderStyleNone;
RTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
RTextField.font = [UIFont fontWithName:@"Helvetica" size:14];
[cell.contentView addSubview:RTextField];
}
}
return cell;
}
Это для образца. Таким образом, секция 0 имеет 6 строк, а секция 1 имеет 3 строки. Где я делаю неправильно. Пожалуйста, помогите мне решить эту проблему.
Заранее спасибо.