![](/img/trans.png)
[英]UITabBarController's moreNavigationController and Navigation Bar
[英]Customize MoreNavigationController's Cell
我正在嘗試制作更多視圖以匹配我的應用程序主題
表格單元格不會改變背景顏色。 我已經嘗試了這里的幾乎所有答案以及互聯網上的博客。
tabBarController?.moreNavigationController.topViewController?.view.backgroundColor = UIColor.blackColor()
我已經使用上面的代碼來實現圖像中顯示的當前場景。
override func viewDidLoad() {
self.homeTableView.registerNib(UINib(nibName: "Banner", bundle: nil), forCellReuseIdentifier: "Banner")
self.homeTableView.registerNib(UINib(nibName: "Heading", bundle: nil), forCellReuseIdentifier: "Heading")
self.homeTableView.registerNib(UINib(nibName: "ThumblessList", bundle: nil), forCellReuseIdentifier: "ThumblessList")
self.homeTableView.registerNib(UINib(nibName: "MapCell", bundle: nil), forCellReuseIdentifier: "MapCell")
self.homeTableView.registerNib(UINib(nibName: "CallButton", bundle: nil), forCellReuseIdentifier: "CallButton")
self.searchBar.showsCancelButton = true
self.edgesForExtendedLayout = UIRectEdge.None
self.extendedLayoutIncludesOpaqueBars = false
self.automaticallyAdjustsScrollViewInsets = false
tabBarController?.moreNavigationController.topViewController?.view.backgroundColor = UIColor.blackColor()
}
這是一個非常晚的答案,但我無法在網上找到這個問題的單一解決方案,即使設置表視圖的顏色和UITabBarController的moreNavaigationController中的單元格應該是你可以在故事板中做的事情。 我覺得這是Swift / xcode devs的疏忽。
也就是說,在UITabBarController
的viewDidAppear
方法中:
override func viewDidAppear(_ animated: Bool) {
if let moreTableView = moreNavigationController.topViewController?.view as? UITableView {
moreTableView.backgroundColor = UIColor.YOURCOLOUR
for cell in moreTableView.visibleCells {
cell.backgroundColor = UIColor.YOURCOLOUR
}
}
}
如果在viewDidLoad
方法中執行此代碼,則此代碼將不起作用。 我希望這段代碼可以幫助那些正在努力尋找解決方案的人!
我最終創建了一個新的視圖控制器,並將其添加為iPhone的第5個標簽項。 對於Ipads,我創建了一個沒有新視圖控制器的單獨故事板。
謝謝:) Sworoop
我遇到了同樣的問題,想分享我解決這個問題的方法。 也許這對其他人有幫助......
為更多的 UITableView 數據源創建一個持有者:
@property (nonatomic, weak, nullable) id moreDataSource;
在代碼中的某處執行以下操作:
if([tabBarController.moreNavigationController.topViewController.view isKindOfClass:UITableView.class]){
UITableView *moreTable = (UITableView*)moreNavController.topViewController.view; self.moreDataSource = moreTable.dataSource; moreTable.dataSource = self;
}
實現UITableViewDataSource
方法:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.moreDataSource tableView:tableView numberOfRowsInSection:section]; }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [self.moreDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor = [UIColor blackColor];
return cell;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.