简体   繁体   中英

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. I feel like this is an oversight from the Swift/xcode devs.

That said, in the viewDidAppear method of your UITabBarController :

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. 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. For Ipads i created a separate storyboard without the new view controller.

Thanks :) 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:

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

  2. Somewhere in the code do the following:

    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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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