2014-11-23 89 views
-1
@IBAction func btnAddSteps(sender: AnyObject) { 
    println("the button was clicked") 
    stepMgr.addSteps(txtSteps.text, desc: txtDesc.text); 
    self.view.endEditing(true) 
    txtSteps.text = "" 
    txtDesc.text = "" 
    self.tabBarController.selectedIndex = 0; 
} 

錯誤寫入上述Swift ???沒有任何成員名?

的UITabBarController代碼後出現?沒有一個名爲selectedIndex的成員

我嘗試了幾種不同的方法,但我可以設法解決。如果有人知道如何使這個運行,請告訴我!

+0

@kupendra你的編輯讓這個問題變得更糟了,因爲你分開了?從標籤欄控制器,當實際上這是一個聲明。 – jrturton 2014-11-23 08:37:27

回答

2
self.tabBarController.selectedIndex = 0; 

您所訪問的視圖控制器的tabBarController屬性,它返回一個可選的(因爲它可能不存在)。

'UITabBarController?'沒有一個名爲「的selectedIndex」成員

可選類型的UITabBarController沒有selectedIndex屬性 - 它只是一個容器,可能會或可能不會保留標籤欄控制器。

您需要使用可選的鏈接:

self.tabBarController?.selectedIndex = 0 

注意的?

如果標籤欄控制器存在,這將打開並設置屬性。