所以我试图在Swift中调用函数“ submitBoilerPlate”:
var url:String = "https://eamorr.com/ajax/getLatestContent.php"
var params = [
"hello":"world"
]
submitBoilerPlate(url, _params:params, _button:nil)
这是对应的功能:
func submitBoilerPlate(_url:String, _params:[String: String!], _button:UIButton?){
var oldTitle = _button?.titleLabel?.text
_button?.setTitle("Please wait...", forState: UIControlState.Normal)
_button?.enabled = false
//etc.
...
}
当我发送在xib上声明的真实UIButton时,一切都会按预期进行。
但是,我希望能够发送“ nil”按钮(此特定的xib没有按钮)。
这可能吗?还是我必须创建一个新功能?我正在尝试将代码重复保持在最低限度...
当代码获取submitBoilerPlate(...)时,出现以下运行时错误:
fatal error: can't unsafeBitCast between types of different sizes
您的问题不在于,UIButton?
而是_params:[String: String!]
如果您在submitBoilerPlate函数中的下面某个地方使用它。尝试将其替换为_params:[String: String]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句