import UIKitclass VIEwController: UIVIEwController,UIActionSheetDelegate{@IBOutlet var button:UIbuttonoverrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw,typically from a nib.}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated.}@IBAction func buttonpressed(AnyObject) { let choice = UIActionSheet(Title: "Select source",delegate: self,cancelbuttonTitle: "Cancel",destructivebuttonTitle: nil,otherbuttonTitles:"camera","libary") choice.showInVIEw(self.vIEw)}}
错误出现在这一行:
let choice = UIActionSheet(Title: "Select source","library")
这是错误文本:
EXC_BAD_ACCESS(代码= 2,地址= 0x0)
我试图将let切换到var,在不同的模拟器上运行它,但结果是一样的.
解决方法 试过,但无法弄清楚异常.最后我得到了这样的解决方案:var myActionSheet:UIActionSheet = UIActionSheet() var Title : String? = "Select Source" myActionSheet.Title = Title myActionSheet.delegate = self myActionSheet.addbuttonWithTitle("camera") myActionSheet.addbuttonWithTitle("library") myActionSheet.addbuttonWithTitle("Cancel") myActionSheet.cancelbuttonIndex = 2 myActionSheet.showInVIEw(self.vIEw)
UIActionSheet代表
func actionSheet(myActionSheet: UIActionSheet!,clickedbuttonAtIndex buttonIndex: Int){ println("the index is %d",buttonIndex) }总结
以上是内存溢出为你收集整理的ios – 尝试在Swift中初始化UIActionSheet时的EXC_BAD_ACCESS全部内容,希望文章能够帮你解决ios – 尝试在Swift中初始化UIActionSheet时的EXC_BAD_ACCESS所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)