![](/img/trans.png)
[英]How do I change the background color of a view controller managed by a UIPageViewController?
[英]Change the background color of “More” view controller
是否可以在UITabBarController的“更多”導航控制器中使用圖像或以其他方式更改單元格的背景顏色?
這些鏈接都不是這個問題的答案。 似乎Malakim指的是UITabBarController
MoreViewController,並且不想更改標簽欄顏色,而是希望更改MoreViewController的tableView的單元格。
答案很簡單。 您可以引用tabBarController的moreViewController屬性,該屬性將為您提供對UIMoreNavigationController
實例的UIMoreNavigationController
。
UINavigationController* moreNavController = myTabController.moreViewController;
然后,使用此導航控制器,您需要根視圖控制器的視圖,因為這就是保持tableView的原因。 實際上,根視圖控制器是UITableViewController
,訪問它的視圖將直接獲取tableView!
UITableView* moreView = ((UIViewController*)[moreNavController.viewControllers objectAtIndex:0]).view;
//可能需要在此處強制顯示以禁止顯示警告
順便說一句,moreView引用了您感興趣的hee tableView。然后,您可以使用moreView.subviews進行深入研究,或者僅進行一個丑陋的背景顏色更改,例如moreView.backgroundColor = [UIColor uglyColor];
Steve給出的方法效果很好,但是當我嘗試將moreNavController的視圖設置為表視圖時,它給了我警告。
warning: incompatible Objective-C types initializing 'struct UIView *', expected 'struct UITableView *'
因此,為了消除警告,我嘗試了下面的代碼,並且它可以正常工作,不確定是否是正確的方法
UINavigationController* moreNavController = self.tabBarController.moreNavigationController; UIViewController* moreViewController = [moreNavController.viewControllers objectAtIndex:0]; moreViewController.view.backgroundColor = [UIColor redColor];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.