Ho aggiunto UINavigationBar nel mio Superview, chiamato BaseViewController, che eredita UIViewController. Ma quando provo a impostare un titolo su UINavigationBar. Ottengo l'errore chiamato errore irreversibile : Impossibile scartare Optional.NoneModifica titolo UINavigationBar in iOS8 Swift
Di seguito è la mia classe veloce. Come può scartare e cambiare il titolo UINavigationBar
import UIKit
class BaseViewConroller: UIViewController {
var navBar:UINavigationBar=UINavigationBar()
override func viewDidLoad() {
super.viewDidLoad()
setNavBarToTheView()
// Do any additional setup after loading the view.
navBar.topItem.title="test test"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setNavBarToTheView()
{
navBar.frame=CGRectMake(0, 0, 320, 50)
navBar.backgroundColor=(UIColor .blackColor())
self.view .addSubview(navBar)
}
}
se l'oggetto facoltativo è nullo, non è possibile scartarlo. Ecco perché ottieni l'errore. Convalida sempre gli oggetti per zero. Come suggerito da Rockey, provare l'errore fatidico di self.title –