【发布时间】:2015-04-28 15:37:36
【问题描述】:
我有一些按钮,按下时会从数组中调用/发送消息。即 button1 将调用数组索引 0 处的数字,button2 索引 1 处的数字,等等。由于某种原因,只要数组中的数字包含 xxx-xxx-xxx 以外的格式,它就会崩溃(即 (xxx) xxx-xxx )。然而,即使数组不为零,日志也会给我以下错误:
有人知道为什么会这样吗? 这是所有内容的代码:
import UIKit
import AddressBook
var contactInfo: [String] = []
[...]
override func viewDidLoad() {
super.viewDidLoad()
//this is the function that grabs the array from an app group
setUpCallMessageButtons()
[...]
callButton1.addTarget(self, action: "call:", forControlEvents: UIControlEvents.TouchUpInside)
}
func call(sender:UIButton!)
{
if (sender == callButton1) {
println("\(contactInfo)")
var url:NSURL? = NSURL(string: "tel:\(contactInfo[0])")
self.extensionContext?.openURL(url!, completionHandler:{(success: Bool) -> Void in
})
}
}
func setUpCallMessageButtons(){
let appGroupID = "**redacted**"
let defaults = NSUserDefaults(suiteName: appGroupID)
contactInfo = (defaults!.objectForKey("contactInfo") as! [String])
println("\(contactInfo)")
//This is gives the log down below. As you can see, none are nil.
}
按钮 1,2 和 5 正常工作,而 3 和 4 总是崩溃。
【问题讨论】: