应用程序在swift中放松时会崩溃

时间:2015-07-20 10:17:22

标签: swift copy-paste unwind-segue

我已使用以下功能将复制粘贴功能实现到文本框中:

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
var result = true
let prospectiveText = (textField.text as NSString).stringByReplacingCharactersInRange(range, withString: string)

if textField == numberField {
  if count(string) > 0 {
  let disallowedCharacterSet = NSCharacterSet(charactersInString: "0123456789").invertedSet
  let replacementStringIsLegal = string.rangeOfCharacterFromSet(disallowedCharacterSet) == nil

  let resultingStringLengthIsLegal = count(prospectiveText) <= 6

  let scanner = NSScanner(string: prospectiveText)
  let resultingTextIsNumeric = scanner.scanDecimal(nil) && scanner.atEnd

  result = replacementStringIsLegal &&
           resultingStringLengthIsLegal &&
           resultingTextIsNumeric
  }
}
return result
}

哪个正常。但是当我们将某些内容粘贴到文本框中并单击后退按钮以取消时,segue应用程序崩溃并发出以下错误:

enter image description here

unwind segue代码:

@IBAction func unwindfromO(segue: UIStoryboardSegue) {


}

0 个答案:

没有答案