infernouk
infernouk

Reputation: 1137

Tab Bar Item hidden behind tableview / not being shown?

I have an empty view with a tab bar pictured below, when i load a routine a table appears containing the contents, however it seems to overlay the tab bar killing off app navigation. Its not sized in the storyboard to overlay it and its constraint locked to not do so, so im unsure why this is happening, pics of the issue and VC's code below:

enter image description here

enter image description here

enter image description here

VC Code:

import Foundation
import UIKit
import CoreData

class RoutineController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    // MARK: - DECLARATIONS

    @IBAction func unwindToRoutine(segue: UIStoryboardSegue) {}
    @IBOutlet weak var daysRoutineTable: UITableView!
    @IBOutlet weak var columnHeaderBanner: UIView!
    @IBOutlet weak var todaysRoutineNavBar: UINavigationBar!
    @IBOutlet weak var addTOdaysRoutineLabel: UILabel!

    let date = Date()
    let dateFormatter = DateFormatter()
    let segueEditUserExerciseViewController = "editExerciseInRoutineSegue"

    //This is the selected routine passed from the previous VC
    var selectedroutine : UserRoutine?

    // MARK: - VIEWDIDLOAD

    override func viewDidLoad() {
        super.viewDidLoad()
        setupView()
        daysRoutineTable.delegate = self
        daysRoutineTable.dataSource = self

        view.backgroundColor = (UIColor.customBackgroundGraphite())

        dateFormatter.dateStyle = .short
        dateFormatter.dateFormat = "dd/MM/yyyy"
        let dateStr = dateFormatter.string(from: date)
        todaysRoutineNavBar.topItem?.title = dateStr + " Routine"
    }

    // MARK: - VIEWDIDAPPEAR

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.daysRoutineTable.reloadData()
        self.updateView()
    }

    // MARK: - TABLE UPDATE COMPONENTS

    private func setupView() {
        updateView()
    }

    // MARK: - TABLE SETUP

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if let count = self.selectedroutine?.userexercises?.count
        {
            print("exercises: \(count)")
            return count
        }
        return 0
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? TodaysRoutineTableViewCell else {
            fatalError("Unexpected Index Path")
        }

        cell.backgroundColor = UIColor.customBackgroundGraphite()
        cell.textLabel?.textColor = UIColor.white
        configure(cell, at: indexPath)

        return cell
    }

    // MARK: - VIEW CONTROLER ELEMENTS VISIBILITY CONTROL

    fileprivate func updateView() {
        var hasUserExercises = false
        if let UserExercise = self.selectedroutine?.userexercises {
            hasUserExercises = UserExercise.count > 0
        }

        addTOdaysRoutineLabel.isHidden = hasUserExercises
        columnHeaderBanner.isHidden = !hasUserExercises
        daysRoutineTable.isHidden = !hasUserExercises
    }

    // MARK: - SETTING DATA FOR A TABLE CELL

    func configure(_ cell: TodaysRoutineTableViewCell, at indexPath: IndexPath) {
        if let userExercise = selectedroutine?.userexercises?.allObjects[indexPath.row]
        {
            print("\((userExercise as! UserExercise).name)")
        cell.todaysExerciseNameLabel.text = (userExercise as! UserExercise).name
        cell.todaysExerciseRepsLabel.text = String((userExercise as! UserExercise).reps)
        cell.todaysExerciseSetsLabel.text = String((userExercise as! UserExercise).sets)
        cell.todaysExerciseWeightLabel.text = String((userExercise as! UserExercise).weight)
        }
    }

}

requested table constraints

enter image description here

Debug hierarchy

enter image description here

The Segue that sends the user back to the view that looses its tab bar

if segue.identifier == "addToTodaySegue" {
    let indexPath = workoutTemplateTable.indexPathForSelectedRow
    let selectedRow = indexPath?.row
    print("selected row\(selectedRow)")
    if let selectedRoutine = self.fetchedResultsController.fetchedObjects?[selectedRow!]
    {
        if let todaysRoutineController = segue.destination as? RoutineController {
            todaysRoutineController.selectedroutine = selectedRoutine
        }
    }
}

I also feel perhaps the viewDidAppear code may cause the issue, perhaps the super class?

    override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    self.daysRoutineTable.reloadData()
    self.updateView()

Updated storyboard image

enter image description here

Upvotes: 0

Views: 604

Answers (3)

shallowThought
shallowThought

Reputation: 19602

I suspect you need to embed your viewController in a UINavigationController.

Consider the following setup:

I suspect your setup is like the upper one:

TapBar -> ViewController -show segue-> ViewController

Which results in a hidden tapbar, like in your description:

While the bottom setup:

TapBar -> NavigationCntroller -rootView-> ViewController -show segue-> ViewController

results in:

which is what you want, how I understood.


Update

It's hard to see. The screenshot of your Storyboard is in pretty low resulution, but the segues look wrong. Double check them. A Segue of type show (e.g push) looks like this:

Also clear project and derived data. Segue type changes sometime are ignored until doing so.

Upvotes: 2

Ajith K Jose
Ajith K Jose

Reputation: 131

The previous suggestion should work. But the content at the bottom part of tableview will not be visible as the tabbar comes over it. So set the bottom constraint of tableview as the height of tabbar.

enter image description here

Upvotes: 0

J. Koush
J. Koush

Reputation: 1068

Try calling this self.view.bringSubviewToFront(YourTabControl).

Upvotes: 0

Related Questions