【发布时间】:2015-01-15 16:35:53
【问题描述】:
我正在尝试在 Swift 中做一些非常简单的事情——实例化一个 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:style:target:action:
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是如何声明的? -
func doSomething() { ... }
-
然后使用
let btn = UIBarButtonItem(image: btnImg, style: .Plain, target: self, action: "doSomthing")注意最后的字符串
标签: ios xcode swift compiler-errors