在我的应用程序中,我有一个选项卡 View Controller ,其中一个选项卡显示体育相关内容。在运动 View 上只有按钮,我从按钮到另一个 View Controller 。当我第一次打开体育事件时,按钮上会显示一个选项卡栏。之后,我单击运动 View Controller 中的一个按钮转到另一个 View Controller ,然后单击返回转到运动 View Controller ,选项卡栏不显示。另外,我在运动 View Controller 中没有代码。这是我单击运动 View Controller 中的按钮后出现的 Controller 之一的代码。后退按钮的代码位于 back_golf 下。我尝试了多种不同的返回方式,但都没有成功!
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.
}
}
最佳答案
不要从 AppDelegate 获取 NavigationController,而是尝试在 GolfViewController 本身上使用 NavigationController,如下所示:
@IBAction func back_golf(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
关于ios - 当我从 View 返回时,标签栏不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50953808/