首先,我很清楚Xcode 6和Swift语言是Beta版本,容易出错.但是,这个特定的对象似乎有些奇怪,因为到目前为止我尝试过的所有其他方法似乎都可以正常工作.
First and foremost, I'm quite aware that Xcode 6 and the Swift language are in Beta and are prone to errors; however, this particular one seems to be something strange as everything else I've tried so far seems to work fine.
如果这不适用于StackOverflow,我将很乐意删除该问题.
If this is not appropriate for StackOverflow, I will gladly remove the question.
我已经开始使用Xcode 6/Swift(为发布做准备),与我想的相比,这是一种非常愉快的体验.话虽如此,移植我喜欢做的训练"风格的应用程序时遇到的一个问题是,由于EXC_BAD_ACCESS所涉及的代码是
I've begin playing with Xcode 6/Swift (preparing for its release) and it has been an extraordinarily enjoyable experience compared to what I thought it would be. That being said, one issue in porting a "training" style app I like to do is that I can't seem to generated a UIAlertView due to EXC_BAD_ACCESS the code in question is:
override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) var alert = UIAlertView(title: "Title", message: "Message", delegate: nil, cancelButtonTitle: "OK") // EXC_BAD_ACCESS here alert.show() }在创建UIAlertView的行上,我得到一个EXC_BAD_ACCESS,因为在已释放的实例上调用了[UIAlertView retain].
On the line that creates the UIAlertView I get an EXC_BAD_ACCESS because [UIAlertView retain] was called on a deallocated instance.
我再次将其用粉笔写到beta横幅上,但是很好奇我做错了什么,或者其他人遇到了类似的问题.
Again, I'm chalking this up to the beta banner but was curious if I was doing something wrong or if anyone else has run into similar issues.
推荐答案尝试以下代码
let alert = UIAlertView() alert.title = "Title" alert.message = "My message" alert.addButtonWithTitle("Ok") alert.show()但是在iOS 8中
UIAlertView已过时.因此,将UIAlertController与UIAlertControllerStyleAlert的preferredStyle一起使用.应该是:
UIAlertView is deprecated. So use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert. It should be:
var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil)检查上面的代码,是否遇到相同的错误?
Check the above code, are you getting same error or not ?
更多推荐
Swift中的UIAlertView,获取EXC
发布评论