0
ここではプロトコルを使用することが初めてです。プロトコル拡張のデフォルト値
私は、mainNavBarItemsというプロトコルを使用する一連のviewcontrollerを持っています。
私は次のようになるが、以下の私のコードでは、誤差の範囲に当たっている:
- は
- 偽デフォルトはViewControllerを をinitialzing時に変数を設定することができrootViewという変数を持っています
- プロトコル拡張機能
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は、UIViewControllerを拡張する必要があります。 – ryantxr
が訂正されました。それは私のコードにあった。 –