Answer the question
In order to leave comments, you need to log in
How to get around Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value?
Controller code:
import UIKit
class ViewController: UIViewController {
func setLogin() {
print("setLogin")
}
var titleField = [
"Hello"
]
var interestingNumbers = [
"fields": [
[
"text": "xxxxx",
"type": "UITextField",
"x": 100,
"y": 100,
"width": 100,
"height": 100
],
[
"text": "yyyy",
"type": "UITextField",
"x": 100,
"y": 100,
"width": 100,
"height": 100
]
]
]
override func viewDidLoad() {
super.viewDidLoad()
let view = HomeView(
structure: interestingNumbers as! [String: ]
)
self.view.addSubview(view)
let user = UserModel(url: "")
user.test()
}
}
import UIKit
class HomeView: UIView {
init(structure: [String : ]) {
super.init(frame: .zero)
print("structure")
self.setupBackground()
for key in structure["fields"]! {
var field: UITextField
switch key["type"]!{
case "UITextField":
field = UITextField()
field.text = key["text"]
field.frame = CGRect(
x: Int(key["x"]!)!,
y: Int(key["y"]!)!,
width: Int(key["width"]!)!,
height: Int(key["height"]!)!
)
self.addSubview(field)
break;
default: break
}
}
}
func setupBackground(){
self.frame = CGRect(x: 0, y: 0, width: 1000, height: 1000)
self.backgroundColor = UIColor(patternImage: UIImage(named: "bg.jpeg")!)
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
blurEffectView.alpha = 0.8
self.addSubview(blurEffectView)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
deinit {
print("deinit HomeView")
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question