vendredi 8 mai 2015

UIView Crash on 2nd call to create UIAlertView

I'm having a weird crash in a custom view. Its a simple debug panel with a button that creates a UIAlertView to grab a string. The XIB links the UIButton to the IBAction on clickInside, and UITextView is linked via the outlet to the mDebugText.

The view controller instantiates the view the first time everything works just fine. I can press the button and the Alertview pops up and I can type and dismiss it. No probpem.

However if my view controller removed/destroys the DebugView and later creates a new one when the button is pressed the app will crash with EXC_BAD_ACCESS. I've stripped out all the extraneous code and this is now down to the bare metal with no delegate on the UIAlertView and its still crashing the 2nd time the view is created and the button is pressed.

If I don't switch views I can press the button, kill the Alert and press again as many times as I like.

Any ideas on what might going wrong would be gratefully received.....

class DebugView : BaseView,UIAlertViewDelegate {

@IBOutlet weak var mDebugText: UITextView!

var mDelegate:DebugViewDelegate? = nil
var mMessage: String = ""

class func instanceFromNib(delegate:DebugViewDelegate? = nil) -> DebugView {
    let view = UINib(nibName: "DebugView", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! DebugView
    view.refreshDisplay()
    view.mDelegate = delegate
    return view
}

override func refreshDisplay() {
    var debug:String = ""
    debug += "STATUS:" + mMessage + "\n\n"
    debug += "\n--END--"
    mDebugText.text = debug
}

@IBAction func onSelectEnterScan(sender: AnyObject) {
    var alertView:UIAlertView = UIAlertView(title: "Fake Scans", message: "Enter Scan Detail", delegate: nil, cancelButtonTitle: "Cancel", otherButtonTitles: "OK")
    alertView.alertViewStyle = UIAlertViewStyle.PlainTextInput;
    alertView.show()
}

}

Aucun commentaire:

Enregistrer un commentaire