我无法将TabBar隐藏在某个视图上

时间:2016-06-16 05:01:54

标签: swift swift2

我想做什么

我正在用TabBarController和NavigationController构建一个应用程序。 storyboard

问题

我试图在使用代码'hidesBottomBarWhenPushed = true'进行转换时隐藏TabBar,但它不能正常工作。 当它转换到'TalkView'时,TabBar会在底部堆栈,直到视图加载为这样: talkview

我认为我的代码中故事板和只是编码混合复杂导致了这个问题。 对不起,我的脏代码......

源代码

// GroupsViewController

    func tableView(TableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let nextVC = storyboard.instantiateViewControllerWithIdentifier("TalkViewController")
        nextVC.hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(nextVC, animated: true)
}

// TalkViewController

override func viewWillAppear(animated: Bool) {

//get the data
self.getMethodOnAlamofire(url){ data in
            dispatch_async(dispatch_get_main_queue()){

                if let _json = data as? NSDictionary{
                     //if it's dictionary, you failed logging in
                    if (_json["error"] as! String == "You should login") {
                        dispatch_async(dispatch_get_main_queue(), {
                            //Move to MainView to get signed in
                            let storyboard = UIStoryboard(name: "Main", bundle: nil)
                            let nextVC = storyboard.instantiateViewControllerWithIdentifier("MainViewController")
                            self.navigationController?.pushViewController(nextVC, animated: false)
                        })
                    }
                }
                    //if it's array, you succeed to get the data properly
                else if let _ = data as? NSArray{
                    //reload the data on TableView
                    self.responseData = data as! NSArray
                    self.originalData = data as? [[String : AnyObject]]
                    self.setupDummyData()
                    self.TableView.delegate = self
                    self.TableView.dataSource = self
                }

                self.reloadTableData(self.responseData!, from:"get")
             }
        }

         self.TableView.setContentOffset(CGPointMake(0, self.TableView.contentSize.height - self.TableView.frame.size.height), animated: false)

    //Scroll to the bottom
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        print("func viewDidLayoutSubview")

        if self.TableView.contentSize.height - self.TableView.bounds.size.height > 0{
            tableViewScrollToBottom(false)
        }
    }

    func tableViewScrollToBottom(animated: Bool) {

        let delay = 0.1 * Double(NSEC_PER_SEC)
        let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))

        dispatch_after(time, dispatch_get_main_queue(), {

            let numberOfSections = self.TableView.numberOfSections
            let numberOfRows = self.TableView.numberOfRowsInSection(numberOfSections-1)

            if numberOfRows > 0 {
                let indexPath = NSIndexPath(forRow: numberOfRows-1, inSection: (numberOfSections-1))
                self.TableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: animated)
            }

        })
    }

    func getMethodOnAlamofire(dataUrl: String, completion: ((data: AnyObject) -> Void)){
        Alamofire.request(.GET, dataUrl)
            .responseJSON { response in
                if response.result.isSuccess{

                    completion(data: response.result.value!)
                    //print(completion)

                }
        }
    }

如果我错过任何我想提及的事情,请告诉我。 提前谢谢。

0 个答案:

没有答案