2012-06-04 21 views
9

Tôi có một UITableViewCell tùy chỉnh làm thay đổi màu sắc trên cơ sở đó hàng đó là in:Làm cách nào để ngăn UITableViewCells tùy chỉnh nhấp nháy màu trắng khi bỏ chọn?

TableViewController.m

- (void)willDisplayCell:(GSRSongCell *)cell atIndexPath:(NSIndexPath *)indexPath; 
{ 
    if (indexPath.row % 2 == 0) { 
     [cell lighten]; 
    } else { 
     [cell darken]; 
    } 
} 

CustomTableViewCell.m

- (void)lighten 
{ 
    self.selectedBackgroundView.backgroundColor = [UIColor whiteColor]; 
    self.contentView.backgroundColor = [UIColor whiteColor]; 
    self.primaryLabel.backgroundColor = [UIColor whiteColor]; 
    self.secondaryLabel.backgroundColor = [UIColor whiteColor]; 
} 
- (void)darken 
{ 
    UIColor *darkColor = [UIColor colorWithR:241 G:241 B:241 A:1]; 
    self.selectedBackgroundView.backgroundColor = darkColor; 
    self.contentView.backgroundColor = darkColor; 
    self.primaryLabel.backgroundColor = darkColor; 
    self.secondaryLabel.backgroundColor = darkColor; 
} 

Tuy nhiên, khi tôi gọi deselectRowAtIndexPath:animated:YES, các hình ảnh động mất dần đến một màu trắng trong các ô có số selectedBackgroundColor sẽ tối hơn.

Sau đó tôi nhận ra rằng hoạt ảnh bỏ chọn không liên quan gì đến số selectedBackgroundColor; trên thực tế, hoạt ảnh deselection thực sự dựa trên thuộc tính tableView.backgroundColor!

Làm cách nào để ghi đè hoạt ảnh bỏ chọn để làm mờ dần màu nền của các ô?

+0

Tôi cũng đã thử đặt tableView.backgroundColor thành [UIColor clearColor] - điều này không có hiệu lực. – oliland

Trả lời

9

Nó thực sự sinh động trở lại màu nền di động, do đó bạn sẽ phải thiết lập nó quá

Thêm dòng này trong phương pháp Lighten

self.backgroundColor = [UIColor whiteColor]; 

và điều này trong phương pháp Darken

self.backgroundColor = darkColor; 
+1

Không thể tin rằng tôi đã không thử điều đó. Cảm ơn bạn! – oliland

3

Just đặt lựa chọn ô thành UITableViewCellSelectionStyleNone trong UIBuilder hoặc trong mã:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
+0

Đối với tôi trong Swift tôi có 'cell.selectionStyle = UITableViewCellSelectionStyle.None' –