简体   繁体   中英

When i go back from view, the tab bar doesn't show

In my app, I have a tab view controller and one of the tabs shows sports related content. On the sports view there is just buttons and I seque from the button to another view controller. When, i first open the sports activity there is a tab bar showing at the button. After, I click on one of the buttons in the sports view controller to go to another view controller, and then click back to go to the sports view controller, the tab bar doesn't show. Also, I have no code in the sports view controller. Here is my code for one of the controllers that appears after clicking on the button in the sports view controller. The code for the back button is under back_golf. I've tried multiple different ways of going back and none of them have worked!

import UIKit
import Firebase

class Golf: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableview_golf: UITableView!

var array = [String]()
var ref : DatabaseReference!
var handle: DatabaseHandle!

@IBAction func back_golf(_ sender: Any) {


    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let navigationController = appDelegate.window?.rootViewController as! UINavigationController

   navigationController.dismiss(animated: true, completion: nil)
     //self.navigationController?.popToRootViewController(animated: true)
    //self.performSegue(withIdentifier: "seque_golf", sender: nil)
    //hidesBottomBarWhenPushed = false
}
override func viewDidLoad() {
    super.viewDidLoad()
    ref = Database.database().reference()
    handle = ref?.child("Girls_golf").observe(.childAdded, with: { (snapshot) in
        if let item = snapshot.value as? String {
            self.array.append(item)
            self.tableview_golf.reloadData()
        }

    })


}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return array.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableview_golf.dequeueReusableCell(withIdentifier: "golf_cell")! as UITableViewCell
    cell.textLabel?.text = array[indexPath.row]
    cell.textLabel?.numberOfLines = 0
    return cell
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

Here is a picture of what i'm doing.

Instead of getting the NavigationController from the AppDelegate, try using the NavigationController on the GolfViewController itself like so:

@IBAction func back_golf(_ sender: Any) {
    self.navigationController?.popViewController(animated: true)
}

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