我一直在關注蘋果教程入門斯威夫特在這裏:https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson3.html#//apple_ref/doc/uid/TP40015214-CH22-SW1設置委託=自導致線程1:exc_bad_instruction(代碼= exc_i386_invop子碼=爲0x0)
我做幾乎同樣的事情,但對於一些原因articleLink.delegate = self
是給我
Thread 1: exc_bad_instruction (code=exc_i386_invop subcode=0x0)
和
fatal error: unexpectedly found nil while unwrapping an Optional value
我真搞不清楚爲什麼發生這種情況,因爲我從字面上繼這部分步蘋果教程一步...
import UIKit
import Alamofire
class ViewController: UIViewController, UITextFieldDelegate {
// MARK: Properties
@IBOutlet weak var articleLink: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Handle the text field's user input through delegate callbacks
articleLink.delegate = self // ERROR OCCURS HERE
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: UITextFieldDelegate
func textFieldShouldReturn(textField: UITextField) -> Bool {
// Hide keyboard
textField.resignFirstResponder()
return true
}
// MARK: Actions
@IBAction func submitLink(sender: AnyObject) {
}
}
謝謝!我對Swift很陌生。我應該如何解決這個問題? – user6091470
這聽起來像是你在該教程中跳過了第8步的一部分,或者在創建斷開連接的插座後進行了更改。您需要檢查您的筆尖中的視圖是否仍然連接到該插座,以下是在此處的界面構建器中可以找到該示例的示例:https://developer.apple.com/library/ios/recipes/xcode_help- IB_connections /章節/ Connections.html#// apple_ref/DOC/UID/TP40014227-CH20-SW1 – Jonah