0
Neu bei der Verwendung von Protokollen hier.Standardwerte in Protokollerweiterungen
Ich habe eine Reihe von Viewcontrollern, die ein Protokoll namens MainNavBarItems verwendet.
Ich möchte folgende, aber mein Code unten eine Reihe von Fehlern trifft:
- haben eine Variable namens RootView die Standardwerte falsch
- der Lage sein, die Variable zu setzen, wenn initialzing die Viewcontroller
- schaffen einen Selektor in den Protokollerweiterungsfunktionen
protocol mainNavBarItems {
var rootView:Bool {get set}
func gotoRootProfileView()
init()
init(rootView:Bool)
}
extension mainNavBarItems{
// how do i set the default to be true?
init(rootView: Bool) {
self.init()
self.rootView = rootView
}
func addMainNavBarItems(){
let s = self as! UIViewController
// ERROR: using a string, but not sure how to define a selector in this case
s.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: s, action: "gotoRootGlobalView")
}
}
class ProfileViewController: UIViewController, mainNavBarItems{
func gotoRootProfileView() {
// does stuff
}
}
// How do i set the boolean for rootview here?
let vc:ProfileViewController = UIStoryboard.getController("Profile", vc: "profileVC")
// ERROR: profileviewcontroller does not have a rootview
vc.rootView = true
AppDelegate.rootGotoWithMainNav(vc)
ProfileViewController hat UIViewController zu verlängern. – ryantxr
korrigiert. Das war in meinem Code. –