我试图创建一些简单的弹出窗口。它只包含2个文本字段和2个按钮 - "取消" &安培; "完成&#34 ;.我已经创建了单独的.xib
模板和NSObject
类。
这是我创建课程并加载.xib
:
class AddressPopup: NSObject, UITextFieldDelegate
{
private var originView: UIView!
private var overlay: UIView!
private var textFieldNumber: UITextField!
private var textFieldStreet: UITextField!
private var buttonDone: UIButton!
private var buttonCancel: UIButton!
var rootView: UIView!
var data = [String:String]()
init(inView rootView: UIView, withData data: [String:String])
{
super.init()
// Set basic data
self.rootView = rootView
self.data = data
// Attach view
self.originView = NSBundle.mainBundle().loadNibNamed("AddressPopup2", owner: self, options: nil)[0] as? UIView
self.originView.layer.cornerRadius = 5
textFieldNumber = originView.viewWithTag(200) as UITextField
textFieldStreet = originView.viewWithTag(201) as UITextField
textFieldNumber.delegate = self
textFieldStreet.delegate = self
// Buttons
buttonDone = originView.viewWithTag(301) as UIButton
buttonCancel = originView.viewWithTag(300) as UIButton
buttonDone.addTarget(self, action: "buttonDoneAction", forControlEvents: .TouchUpInside)
}
// Other methods
每当我尝试将其中一个文本字段作为第一响应者或点击done
按钮应用程序崩溃而没有任何描述时。只需打印(lldb)
即可。如果我删除行,将委托设置为textfields - 一切正常。或者,如果我删除addTarget
应用的行,则不会崩溃。
我知道我的文字字段不是零,因为我可以设置一些文字。我无法弄清楚导致坠机的原因。