2014-04-03 71 views
0

我在iOS7故事板中使用靜態單元格。單元格中有UIButtons,它們依次調用「selectRowAtIndexPath」方法。UITableView selectedBackgroundView不覆蓋整個單元格

enter image description here

enter image description here

這不是一個一致的行爲,當我在小區間切換纔會發生。

這裏有問題的兩個單元有一個共同的超類。這裏是代碼:

@implementation StudentMenuMultipleOptionsTableViewCell 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:selected animated:animated]; 

    if (!selected) { 
     for (UIView *view in self.contentView.subviews) { 
      if ([view isKindOfClass:[BlackBackgroundSelectedButton class]]) { 
       BlackBackgroundSelectedButton *button = (BlackBackgroundSelectedButton *)view; 
       button.selected = NO; 
       [button setWhite]; 
      } 
     } 
    } 
} 

@end 

回答

0

非常棘手。

您需要確保您沒有對多個單元格使用相同的UIView。只要使用過一次,視圖就會調整大小,並會造成尺寸問題。

的解決方案是創建一個單獨的背景視圖對每個小區像這樣:

enter image description here