2013-04-21 186 views
0

我有一個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/

這我是第一次在這裏發佈問題,所以請原諒我,如果有任何錯誤。任何在這方面的幫助將非常感激。提前致謝。

回答

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; 
} 
相關問題