我在UITableview分组样式中有两个部分有一个问题。第一部分有6排,第二部分有3排。当我上下滚动tableview时,第2节的最后一行内容将添加到第一节的第一行,并且第一节的第一行内容将添加到第二节的最后一行。我最好检查一下自己的级别,以确定单元格是否为空来加载内容,但在调试时不会发生。我的代码是,UITableview部分覆盖在iPhone?
- (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行。我在哪里做错了。请帮我解决这个问题。
在此先感谢。
细胞可重复使用,以提高性能,您应仔细阅读苹果的文档,并为UITableView的部分基本上是和重要性。 –