我正在用xcode创建一个应用程序,每次我在模拟器中运行时,初始视图控制器都可以正常工作,但是当我导航到UItabbarcontroller
时,我可以看到底部的选项卡栏,但屏幕为黑色。我该如何解决?
情节提要:
https://i.stack.imgur.com/O9jxb.png
第一个ViewController代码:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
第二个Viewcontroller代码:
import UIKit
class fit1: UITabBarController {
@IBOutlet weak var namef: UITextField!
@IBOutlet weak var typef: UITextField!
@IBOutlet weak var repf: UITextField!
@IBOutlet weak var calf: UITextField!
@IBOutlet weak var text: UITextView!
@IBAction func create(_ sender: UIButton) {
text.text = "Name: \(namef.text!)\nType: \(typef.text!)\nRep/Time: \(repf.text!)\nCalories: \(calf.text!)"
}
func fitscreen2(){
namef.delegate = self
typef.delegate = self
repf.delegate = self
calf.delegate = self
}
}
extension UITabBarController: UITextFieldDelegate{
public func textFieldShouldReturn(_ text: UITextField) -> Bool {
text.resignFirstResponder()
return true
}
}
第三种视图控制器代码:
import UIKit
class fit2: UITabBarController {
}
我已在此屏幕截图中复制了错误。就像我说的那样,第一个视图控制器工作正常,只有当我点击健身按钮时,打开UITabBarcontroller屏幕才会变黑:
https://i.stack.imgur.com/S98BC.png
[编辑]
在进一步的努力下,我可以看到是否将空白的viewcontroller放入主类中,它可以正常工作,只有当我将它们放入类中时,它才行不通,所以也许与我分配给的类有关视图控制器?
如您在这些屏幕截图中所见,这就是我将视图控制器分配给其类的方式。
https://i.stack.imgur.com/El5jH.png https://i.stack.imgur.com/8yaWy.png