我有一个空白视图,下面是一个标签栏,当我加载一个例程时,会出现一个包含内容的表格,但是它似乎覆盖了标签栏,从而消除了应用程序导航。它没有在故事板中调整以覆盖它并且其约束被锁定而不是这样,所以我不确定为什么会发生这种情况,问题的图片和VC的代码如下:
VC代码:
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)
}
}
}
请求的表约束
调试层次结构
将用户发送回丢失其标签栏
的视图的Segueif 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
}
}
}
我也觉得viewDidAppear代码可能会导致问题,也许是超类?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.daysRoutineTable.reloadData()
self.updateView()
更新了故事板图片
答案 0 :(得分:2)
我怀疑你需要将viewController嵌入UINavigationController
。
考虑以下设置:
我怀疑你的设置就像上面那样:
TapBar -> ViewController -show segue-> ViewController
这导致隐藏的标准栏,如您的说明所示:
底部设置:
TapBar -> NavigationCntroller -rootView-> ViewController -show segue-> ViewController
结果:
这就是你想要的,我的理解。
<强>更新强>
很难看出来。你的故事板的屏幕截图是相当低的,但segues看起来错了。仔细检查一下。 show (e.g push)
类型的Segue看起来像这样:
还清除项目和派生数据。在某些时候,Segue类型的更改会被忽略,直到这样做。
答案 1 :(得分:0)
尝试调用此self.view.bringSubviewToFront(YourTabControl)
。
答案 2 :(得分:0)