2013-10-16 85 views
-2

我有一個UITableview和UICutsom單元格。在那個UITableview中,我使用Web服務填充數據。我改變單元格的背景顏色和字體顏色。當我上下滾動Tableview單元格時,背景顏色和標籤顏色也會在另一個單元格上發生變化。與UITableview UIScrollView問題

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"FieldInventoryCell"; 

    // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    FieldInventoryCell *cell=(FieldInventoryCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil) { 

     NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"FieldInventoryCell" owner:self options:nil]; 

     cell=[nib objectAtIndex:0]; 
    } 

    NSArray *ar = [[arr objectAtIndex:indexPath.row]componentsSeparatedByString:@"|"]; 
    cell.Status.text=[ar objectAtIndex:1]; 
    cell.serialnumber.text=[ar objectAtIndex:0]; 
    cell.date.text=[ar objectAtIndex:2]; 

    if([cell.serialnumber.text isEqualToString:@"Grand Total"]) 
    { 

     cell.contentView.backgroundColor=[UIColor blueColor]; 
     cell.serialnumber.textColor=[UIColor whiteColor]; 

    } 
    if ([cell.serialnumber.text isEqualToString:@"INV_FLD Status Total"]) 
    { 
     //cell.contentView.backgroundColor=[UIColor blueColor]; 
     cell.serialnumber.textColor=[UIColor orangeColor]; 

    } 


    return cell; 

} 
+1

您尚未描述(或者突出顯示)實際問題。你面臨什麼問題?你有什麼試圖解決它? –

回答

0

據我的理解,你可能遇到的問題與出列單元格有關。您正在爲contentView和序列號標籤設置一些顏色,但如果條件未滿足,則不會重置它們。由於表格重複使用單元格,因此您的已着色的項目將顯示新元素。爲了解決這個問題,請將顏色重置爲默認值,即類似於

// ... 
if([cell.serialnumber.text isEqualToString:@"Grand Total"]) 
{ 

    cell.contentView.backgroundColor=[UIColor blueColor]; 
    cell.serialnumber.textColor=[UIColor whiteColor]; 

} else { 
    // reset color 
    cell.contentView.backgroundColor=[UIColor clearColor]; 
    cell.serialnumber.textColor=[UIColor blackColor]; 
} 

if ([cell.serialnumber.text isEqualToString:@"INV_FLD Status Total"]) 
{ 
    //cell.contentView.backgroundColor=[UIColor blueColor]; 
    cell.serialnumber.textColor=[UIColor orangeColor]; 

} else { 
    // reset color 
    cell.serialnumber.textColor=[UIColor blackColor]; 
}