ios - 当我从 View 返回时,标签栏不显示

标签 ios swift uibutton back

在我的应用程序中,我有一个选项卡 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.
}
}

Here is a picture of what i'm doing.

最佳答案

不要从 AppDelegate 获取 NavigationController,而是尝试在 GolfViewController 本身上使用 NavigationController,如下所示:

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

关于ios - 当我从 View 返回时,标签栏不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50953808/

相关文章:

iphone - Swift 版本的 Obj.C 宏 : IS_RETINA

ios - 当似乎没有错误时如何处理我的应用程序中的错误

ios - 进度动画 UIButton

iphone - UIButton 触摸时缩放?

ios - 两个相同的 CGSize,一个看起来更小

iOS Metal - 渲染一个完整的三角形

ios - 如何在应用程序中使用 iOS 的内置文本转语音功能?

ios - BOOL UIButton 上的按钮选择

ios - 使用 UIScrollView 的渐变背景颜色

ruby-on-rails - AFNetworking HTTPClient 从 Rails JSON 服务接收 406