簡體   English   中英

訪問moreNavigationController的UITableView的-willDisplayCell方法

[英]Accessing -willDisplayCell method of moreNavigationController's UITableView

在moreNavigationController中設置UITableView的backgroundView后,像這樣...

UITableView *moreTableView = (UITableView *)tabBarController.moreNavigationController.topViewController.view;
[moreTableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]]];

...該UITableView的單元格將backgroundColor從白色更改為透明(透明)。 我嘗試使用以下代碼行將其設置為白色...

for (UITableViewCell *cell in [moreTableView visibleCells]) {
    [cell setBackgroundColor:[UIColor whiteColor]];
}

...但是不幸的是,這不起作用,所以我猜唯一的解決方案是在-willDisplayCell:方法中設置backgroundColor。 誰能告訴我如何使用該方法? 任何幫助將不勝感激。

如果您有一個自定義單元格,則可以在UITabeViewCell的子類中設置該單元格的背景色,否則應嘗試將此邏輯添加到UITableView數據源的tableView:cellForRowAtIndexPath:方法。

您在循環中所做的操作只會影響可見的單元格,因為它們將被重用,並且如果將背景設置為動態清除,那么您將始終覆蓋背景。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM