我試圖做一些斯威夫特很簡單 - 實例化的UIBarButtonItem:通過編程實例的UIBarButtonItem拋出缺少參數異常
let btnImg = UIImage(named: "imgName")
let btn = UIBarButtonItem(image: btnImg, style: .Plain, target: self, action: doSomthing)
該代碼產生構建失敗:
Missing argument for parameter 'landcapeImagePhone' in call
據the docs ,這兩種功能都可用:
initWithImage:style:target:action:
init(image image: UIImage?,
style style: UIBarButtonItemStyle,
target target: AnyObject?,
action action: Selector)
initWithImage:landscapeImagePhone:風格:目標:動作:
init(image image: UIImage?,
landscapeImagePhone landscapeImagePhone: UIImage?,
style style: UIBarButtonItemStyle,
target target: AnyObject?,
action action: Selector)
如果我雖然執行第二初始化,我得到以下錯誤:
Extra argument 'landscapeImagePhone' in call
有誰知道一種我可以實現我想要實現的方式?這是Swift/Xcode中的錯誤嗎?我正在運行Xcode 6.1.1。我已經做了一個乾淨的(Cmd + SHIFT + K)和生成文件夾乾淨(Cmd + ALT + SHIFT + K)。
如何'doSomthing'聲明? – gabuh 2015-01-15 16:40:44
func doSomething(){...} – djbp 2015-01-15 16:47:16
然後使用'let btn = UIBarButtonItem(image:btnImg,style:.Plain,target:self,action:「doSomthing」)'注意末尾的字符串 – gabuh 2015-01-15 16:48:39