我有一个UITableView,我在使用自定义UITableViewCell。一切都很好,直到滚动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/
这是我第一次在这里发帖提问,如果有任何错误,请原谅我。在这方面的任何帮助将非常感谢。提前谢谢。
答案 0 :(得分:0)
试试这个
- (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;
}