简体   繁体   English

自定义 MoreNavigationController 的 Cell

[英]Customize MoreNavigationController's Cell

I am trying to make the more view to match my app theme我正在尝试制作更多视图以匹配我的应用程序主题

在此处输入图片说明

The table cells are not changing background color.表格单元格不会改变背景颜色。 I have tried almost all the answers here and blogs over the internet.我已经尝试了这里的几乎所有答案以及互联网上的博客。

tabBarController?.moreNavigationController.topViewController?.view.backgroundColor = UIColor.blackColor()

I have used the above code to achieve the current scenario shown in image.我已经使用上面的代码来实现图像中显示的当前场景。

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()
}

This is a very late answer, but I could not find a single solution to this problem anywhere online, even though setting the colour of the table view and the cells in the moreNavaigationController of a UITabBarController should be something you can do in the storyboard. 这是一个非常晚的答案,但我无法在网上找到这个问题的单一解决方案,即使设置表视图的颜色和UITabBarController的moreNavaigationController中的单元格应该是你可以在故事板中做的事情。 I feel like this is an oversight from the Swift/xcode devs. 我觉得这是Swift / xcode devs的疏忽。

That said, in the viewDidAppear method of your UITabBarController : 也就是说,在UITabBarControllerviewDidAppear方法中:

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
        }
    }
}

This code will not work if you do it in the viewDidLoad method. 如果在viewDidLoad方法中执行此代码,则此代码将不起作用。 I hope this code helps someone who is struggling to find a solution! 我希望这段代码可以帮助那些正在努力寻找解决方案的人!

I ended up creating a new view controller and adding that as a 5th tab item for iPhones. 我最终创建了一个新的视图控制器,并将其添加为iPhone的第5个标签项。 For Ipads i created a separate storyboard without the new view controller. 对于Ipads,我创建了一个没有新视图控制器的单独故事板。

Thanks :) Sworoop 谢谢:) Sworoop

I faced with the same issue and want to share my approach to solve this problem.我遇到了同样的问题,想分享我解决这个问题的方法。 Maybe it will be helpful for someone else...也许这对其他人有帮助......

  1. Create a holder for the more UITableView data source:为更多的 UITableView 数据源创建一个持有者:

    @property (nonatomic, weak, nullable) id moreDataSource; @property (nonatomic, weak, nullable) id moreDataSource;

  2. Somewhere in the code do the following:在代码中的某处执行以下操作:

    if([tabBarController.moreNavigationController.topViewController.view isKindOfClass:UITableView.class]){ if([tabBarController.moreNavigationController.topViewController.view isKindOfClass:UITableView.class]){

     UITableView *moreTable = (UITableView*)moreNavController.topViewController.view; self.moreDataSource = moreTable.dataSource; moreTable.dataSource = self;

    } }

  3. implement methods of the UITableViewDataSource :实现UITableViewDataSource方法:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.moreDataSource tableView:tableView numberOfRowsInSection:section]; -(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM