滚动时自定义单元格重新加载问题UITableView
问题描述:
我有一个UITableView在我使用自定义UITableViewCell。一切都很好,直到UITableView滚动。只要我滚动UITableView在第二部分中的单元格开始显示第一部分中的单元格的内容。滚动时自定义单元格重新加载问题UITableView
我为我的项目使用了Storyboard。
这里是的cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
LS_Custom_Cell *customCell = (LS_Custom_Cell *)[tableView dequeueReusableCellWithIdentifier:@"LS_Custom_Cell" forIndexPath:indexPath];
if (indexPath.section == 0 && indexPath.row == 0) {
customCell.selectionStyle = UITableViewCellSelectionStyleNone;
[customCell.btnAddContact addTarget:self
action:@selector(btnAddContactAction:)
forControlEvents:UIControlEventTouchDown];
customCell.btnSelectContact.hidden = YES;
customCell.btnAddContact.hidden = NO;
customCell.lblAddContactText.hidden = NO;
customCell.lblContactName.hidden = YES;
customCell.lblContactEmailId.hidden = YES;
}else if (indexPath.section == 1){
customCell.lblContactName.text = [NSString stringWithFormat:@"%@", [[contactsArray objectAtIndex:indexPath.row] valueForKey:@"name"]];
customCell.lblContactEmailId.text = [NSString stringWithFormat:@"%@", [[contactsArray objectAtIndex:indexPath.row] valueForKey:@"email"]];
}
return customCell;
}
我也是为了进一步澄清这个问题以图片的代码。
这张截图是第一次表负荷记录似乎完美的,当
http://postimg.org/image/y2114vjdl/
只要我开始从第一部分滚动细胞出现在第二部分
http://postimg.org/image/c5ei4i66x/
这我是第一次在这里发布问题,所以请原谅我,如果有任何错误。任何在这方面的帮助将非常感激。提前致谢。
答
试试这个
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
LS_Custom_Cell *customCell = (LS_Custom_Cell *)[tableView dequeueReusableCellWithIdentifier:@"LS_Custom_Cell" forIndexPath:indexPath];
if (indexPath.section == 0 && indexPath.row == 0)
{
customCell.selectionStyle = UITableViewCellSelectionStyleNone;
[customCell.btnAddContact addTarget:self
action:@selector(btnAddContactAction:)
forControlEvents:UIControlEventTouchDown];
customCell.btnSelectContact.hidden = YES;
customCell.btnAddContact.hidden = NO;
customCell.lblAddContactText.hidden = NO;
customCell.lblContactName.hidden = YES;
customCell.lblContactEmailId.hidden = YES;
}
else if (indexPath.section == 1)
{
customCell.btnSelectContact.hidden = NO;
customCell.btnAddContact.hidden = YES;
customCell.lblAddContactText.hidden = YES;
customCell.lblContactName.hidden = NO;
customCell.lblContactEmailId.hidden = NO;
customCell.lblContactName.text = [NSString stringWithFormat:@"%@", [[contactsArray objectAtIndex:indexPath.row] valueForKey:@"name"]];
customCell.lblContactEmailId.text = [NSString stringWithFormat:@"%@", [[contactsArray objectAtIndex:indexPath.row] valueForKey:@"email"]];
}
return customCell;
}