最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】Cannot invoke initializer for type UIAlertController with an argument list of type title delegate

Swift crifan 4659浏览 0评论

【问题】

swift中,在把UIActionSheet换成了UIAlertController之后,代码变成:

    func changeHeadAction(button : UIButton) {
        print("changeHeadAction()")
        photoActionController = UIAlertController(title: nil, delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "从相册选择","拍照")

  出错:

MyViewController.swift:312:33: Cannot invoke initializer for type ‘UIAlertController’ with an argument list of type ‘(title: NilLiteralConvertible, delegate: MyViewController, cancelButtonTitle: String, destructiveButtonTitle: NilLiteralConvertible, otherButtonTitles: String, String)’

如图:

Cannot invoke initializer for type UIAlertController with an argument list of type

 

【解决过程】

1.很明显是:

需要重新写创建UIAlertController的代码,参数都不一样了。

搜:

Cannot invoke initializer for type UIAlertController with an argument list of type title delegate

参考:

参考之前的:

UIAlertController Class Reference

去重写初始化代码:

结果当上述页面中,点击了swift后,没有示例代码了。

搞得只能自己想办法了。

又找不到源码。

2.想到了,用command+鼠标点击UIAlertController

是可以跳转到swift源码中的:

command mouse click jump to UIAlertController sourcecode

所以,去看了代码后,自己尝试写初始化代码:

结果还是不会写。

3.搜:

how to use UIAlertController

参考:

UIAlertController Example in iOS

UIAlertController Changes in iOS 8 – Use Your Loaf

4.搜:

UIAlertController swift example

参考:

UIAlertController Swift Example

 

【总结】

算了,不去研究了。

因为暂时有别人去研究。

转载请注明:在路上 » 【未解决】Cannot invoke initializer for type UIAlertController with an argument list of type title delegate

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.161 seconds, using 22.08MB memory