自定义 MoreNavigationController 的 Cell
Customize MoreNavigationController's Cell
我正在尝试让更多视图与我的应用主题相匹配
table 单元格没有改变背景颜色。我已经尝试了几乎所有这里的答案和互联网上的博客。
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()
}
我最终创建了一个新的视图控制器并将其添加为 iPhone 的第 5 个选项卡项。对于 Ipad,我创建了一个没有新视图控制器的单独故事板。
谢谢:)
飞翔
这是一个很晚的答案,但我无法在网上任何地方找到这个问题的单一解决方案,即使设置 table 视图的颜色和 UITabBarController 的 moreNavaigationController 中的单元格应该是你可以在情节提要中做的事情。我觉得这是 Swift/xcode 开发人员的疏忽。
就是说,在您 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
方法中执行此代码,则此代码将不起作用。我希望这段代码可以帮助正在努力寻找解决方案的人!
我遇到了同样的问题,想分享我解决这个问题的方法。也许对其他人有帮助...
为more UITableView数据源创建一个holder:
@属性(非原子、弱、可为空)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.moreDataSourcetableView:tableViewnumberOfRowsInSection:section];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [self.moreDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor = [UIColor blackColor];
return cell;
}
我正在尝试让更多视图与我的应用主题相匹配
table 单元格没有改变背景颜色。我已经尝试了几乎所有这里的答案和互联网上的博客。
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()
}
我最终创建了一个新的视图控制器并将其添加为 iPhone 的第 5 个选项卡项。对于 Ipad,我创建了一个没有新视图控制器的单独故事板。
谢谢:) 飞翔
这是一个很晚的答案,但我无法在网上任何地方找到这个问题的单一解决方案,即使设置 table 视图的颜色和 UITabBarController 的 moreNavaigationController 中的单元格应该是你可以在情节提要中做的事情。我觉得这是 Swift/xcode 开发人员的疏忽。
就是说,在您 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
方法中执行此代码,则此代码将不起作用。我希望这段代码可以帮助正在努力寻找解决方案的人!
我遇到了同样的问题,想分享我解决这个问题的方法。也许对其他人有帮助...
为more UITableView数据源创建一个holder:
@属性(非原子、弱、可为空)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.moreDataSourcetableView:tableViewnumberOfRowsInSection:section]; }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [self.moreDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor = [UIColor blackColor];
return cell;
}