![](/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.