2016-06-28 4 views
0

現在、テーブルビューにはクリアな背景色があり、その下の画像を見ることができます。テーブルビューの背景はシミュレータで表示されますが、デバイス上で再生すると白です

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

View Hierarchy Inspectorを使用して、白い背景の原因を確認します。 – EmilioPelaez

+0

あなたのコードはどのように見えますか?どのように背景画像を設定していますか? – ZGski

+0

元の投稿にコードを追加しました。それはTabBarControllerのmoreViewControllerのためです。 – SwiftyJD

答えて

0

次のコードを追加しようと、それは二つの理由があるかもしれない私の場合には

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

これが解決策である理由を説明する単語を追加できますか? – mustaccio

0

を働きました。 uitableviewcellの背景が明確でない 実行中のプロジェクトターゲットに画像参照が追加されていません。それは何度か起こる。 PLZのダブルチェック。