Problems with getting text from UIAlertView textfield

前端 未结 4 886
滥情空心
滥情空心 2020-12-15 13:08

In my application I want a alert with a textfield. After clicking on \"Done\" I want to save the textfield input in a String. After clicking on \"Cancel\" I want only to clo

4条回答
  •  暖寄归人
    2020-12-15 13:38

    For iOS 8+ you should use UIAlertController instead of UIAlertView. To support iOS 7 you should implement (UIAlertViewDelegate):

    func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int)
    {
        //...
        let textField = alertView.textFieldAtIndex(0)
    }
    

提交回复
热议问题