2013-07-03 43 views
0

我想爲我的應用程序中的所有UITableViewCell配件視圖設置自定義圖像。我試過使用此代碼:使用UIAppearance代理的自定義UITableViewCell

[[UITableViewCell appearance] setAccessoryView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"table-arrow.png"]]]; 

但它不起作用。

任何想法?

回答

3

嘗試在UITableViewCell的類創建自定義外觀選擇。下面是一個示例實現:

.H:

- (void)setAccessoryViewImage:(UIImage *)image UI_APPEARANCE_SELECTOR; 

.M:

- (void)setAccessoryViewImage:(UIImage *)image { 
    self.accessoryView = [[UIImageView alloc] initWithImage:image]; 
} 

而且比你可以使用代理對象配置所有的細胞:

[[UITableViewCell appearance] setAccessoryViewImage:[UIImage imageNamed:@"table-arrow.png"]]; 
+0

天才,沒有意識到它很容易添加UI_APPEARANCE_SELECTORs視圖。 – powerj1984

1

//試試這個

cell.accessoryType = UITableViewCellAccessoryNone; 
    UIImageView *imgArrow = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 15)] ; 
    imgArrow.image = [UIImage imageNamed:@"table-arrow.png"]; 
    cell.accessoryView = imgArrow; 
    [imgArrow release]; 
    imgArrow = nil; 
+0

感謝您回答,但我需要使用Apperance Proxy來做到這一點,以避免對我的a中的每個單一屏幕控制器執行此操作第 – Claus