2016-04-12 32 views
0

Protokolleri burada kullanmak yeni.Protokol uzantılarında varsayılan değerler

mainNavBarItems adlı bir protokol kullanan bir dizi denetleyicim var.

Aşağıdaki ama benim kod aşağıda hataların bir dizi vuruyor istiyorum:

  • sahip viewcontroller
  • initialzing zaman
  • değişkeni ayarlamak mümkün sahte varsayılan değişken denilen rootView protokol uzatma fonksiyonlarda bir seçici oluşturmak

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) 
+0

ProfileViewController UIViewController genişletmek için yer alır. – ryantxr

+0

düzeltildi. Bu benim kodumdaydı. –

cevap

0

ProfileViewController, mainNavBarItems protokolünün rootView özelliğine sahip değildir. ... ve Protokolün büyük harfli adları olmalıdır.

Protocol as Types

İlgili konular