当我从视图返回时,标签栏不显示
When i go back from view, the tab bar doesn't show
在我的应用程序中,我有一个选项卡视图控制器,其中一个选项卡显示与体育相关的内容。在运动视图上只有按钮,我从按钮到另一个视图控制器。当我第一次打开运动 activity 时,按钮上显示了一个标签栏。之后,我单击运动视图控制器中的一个按钮转到另一个视图控制器,然后单击返回转到运动视图控制器,标签栏不显示。另外,我在运动视图控制器中没有代码。这是我在单击运动视图控制器中的按钮后出现的其中一个控制器的代码。后退按钮的代码在 back_golf 下。我尝试了多种不同的返回方式,其中 none 成功了!
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.
不要从 AppDelegate 获取 NavigationController,而是尝试在 GolfViewController 本身上使用 NavigationController,如下所示:
@IBAction func back_golf(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
在我的应用程序中,我有一个选项卡视图控制器,其中一个选项卡显示与体育相关的内容。在运动视图上只有按钮,我从按钮到另一个视图控制器。当我第一次打开运动 activity 时,按钮上显示了一个标签栏。之后,我单击运动视图控制器中的一个按钮转到另一个视图控制器,然后单击返回转到运动视图控制器,标签栏不显示。另外,我在运动视图控制器中没有代码。这是我在单击运动视图控制器中的按钮后出现的其中一个控制器的代码。后退按钮的代码在 back_golf 下。我尝试了多种不同的返回方式,其中 none 成功了!
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.
不要从 AppDelegate 获取 NavigationController,而是尝试在 GolfViewController 本身上使用 NavigationController,如下所示:
@IBAction func back_golf(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}