2016-06-28 54 views
0

我目前有一个清晰的背景颜色的tableview,因此可以看到它下面的图像。在模拟器它的伟大工程:Tableview背景在模拟器上显示,但在设备上播放时显示为白色

enter image description here

但是,当它的设备上播放的背景变为白色:

enter image description here

的应用仍然正常工作,但它会是不错的保持背景图片。 这是我的代码:

class TabBarController: UITabBarController, UITableViewDelegate, UITableViewDataSource { 



    var tabBarItems: [UIViewController] = [] 
    var areMessagesVisible: Bool = false 

    var titleForTabBars: [String] = ["Home", "Inbox", "Rewards", "My Card", "Locations", "My Profile", "Account Activity", "Invite Friends", "About Us", "Settings", "Help"] 

    var iconNames: [String] = ["Glass", "Mail Tab Bar Icon", "Rewards Tab Bar Icon", "TabBar card icon", "Locations Tab Bar Icon", "", "", "","","",""] 

    var controllersStoryboardId: [String] = ["homeNavController", "inboxNavController", "rewardsNavController", "cardNavController", "locationsNavController", "myProfileNavController", "accountActivityNavController", "inviteFriendsNavController", "aboutUsNavController", "settingsNavController", "helpNavController" ] 



    // to manage moreTableView 
    var moreTableView: UITableView = UITableView() 
    var currentTableViewDelegate: UITableViewDelegate? 




    override func viewDidLoad() { 
    super.viewDidLoad() 

    self.customizeMoreTableView() 
    //to REMOVE 
    areMessagesVisible = true 

    if !areMessagesVisible{ 
     self.titleForTabBars.removeAtIndex(4) 
     self.controllersStoryboardId.removeAtIndex(4) 
     self.iconNames.removeAtIndex(4) 
    } 

    for i in 0 ..< controllersStoryboardId.count{ 
     tabBarItems.append(UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier(controllersStoryboardId[i]) as? UINavigationController ?? UINavigationController()) 
    } 


    // change background image 
    let backgroundImageView = UIImageView(image: UIImage(named: "Blank Settings")) 
    backgroundImageView.frame = view.frame 
    backgroundImageView.contentMode = .ScaleAspectFill 
    moreNavigationController.topViewController?.view.addSubview(backgroundImageView) 
    moreNavigationController.topViewController?.view.sendSubviewToBack(backgroundImageView) 

    let backgroundImageView2 = UIImageView(image: UIImage(named: "background3")) 
    backgroundImageView2.frame = view.frame 
    backgroundImageView2.contentMode = .ScaleAspectFill 
    moreNavigationController.topViewController?.view.addSubview(backgroundImageView2) 
    moreNavigationController.topViewController?.view.sendSubviewToBack(backgroundImageView2) 


    //change nav bar color 
     moreNavigationController.navigationBar.barStyle = UIBarStyle.BlackOpaque 
     moreNavigationController.navigationBar.barTintColor = UIColor.blackColor() 
     moreNavigationController.navigationBar.tintColor = UIColor.whiteColor() 

    } 




    override func viewWillAppear(animated: Bool) { 

    for i in 0 ..< tabBarItems.count{ 
     tabBarItems[i].tabBarItem = UITabBarItem(title: titleForTabBars[i], image: UIImage(named: iconNames[i]), selectedImage: UIImage(named: iconNames[i])) 
    } 
    self.viewControllers = tabBarItems 
    } 


    func customizeMoreTableView(){ 
    moreTableView = self.moreNavigationController.topViewController!.view as? UITableView ?? UITableView() 
    currentTableViewDelegate = moreTableView.delegate; 
    moreTableView.delegate = self 
    moreTableView.dataSource = self; 
    moreTableView.registerClass(MoreTableViewCell.self, forCellReuseIdentifier: "MoreTableViewCell") 

    } 


    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    return 50 
    } 


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let moreCell = tableView.dequeueReusableCellWithIdentifier("MoreTableViewCell", forIndexPath: indexPath) as? MoreTableViewCell ?? MoreTableViewCell() 

    moreCell.textLabel?.text = titleForTabBars[indexPath.row + 4] 
    moreCell.textLabel?.textColor = UIColor.whiteColor() 
    moreCell.imageView?.image = UIImage(named: iconNames[indexPath.row + 4]) 
    moreCell.backgroundColor = UIColor.clearColor() 

    return moreCell 
    } 


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return titleForTabBars.count - 4 

    } 


    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    currentTableViewDelegate?.tableView!(tableView, didSelectRowAtIndexPath: indexPath) 
    } 

} 
+1

使用“查看层次结构检查器”查看导致白色背景的原因。 – EmilioPelaez

+0

你的代码是什么样的?你如何设置背景图像? – ZGski

+0

我将代码添加到原始文章中,它是为更多的ViewController关闭TabBarController – SwiftyJD

回答

0

在你的tableview数据源尝试添加以下代码,并在我的情况下工作

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    var cell=tableView.dequeueReusableCellWithIdentifier("cellidentifier")! 
    cell.backgroundColor=UIColor.clearColor() 
    return cell 
} 
+0

可能您可以添加几个词来解释为什么这是一个解决方案? – mustaccio

0

可能有两个原因。 uitableviewcell背景不清晰 您的图像参考未添加到您正在运行的项目目标中。它发生了一些时间。双重检查。

相关问题