close
剛好遇到有客戶  對應的版本是從 iOS7 開始  但是AlertView 的用法真的是天差地遠啊
                  if #available(iOS 8.0, *) 
                  {//版本是iOS 8.0 以上
                    let alertController = UIAlertController(title: "", message: "", preferredStyle: .Alert)

                    let sendAction = UIAlertAction(title: "OK", style: .Default)
                    { (_) in
                         // 這個按鈕按下去要做的事情
                    }
                    
                    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel)
                    { (_) in
                         // 這個按鈕按下去要做的事情
                    }
                    
                    alertController.addTextFieldWithConfigurationHandler
                    { (textField) in
                         //增加一個文字輸入框
                         textField.text = ""//設定輸入框的內容
                    }
                    
                    alertController.addAction(cancelAction)//加按鈕
                    alertController.addAction(sendAction)//加按鈕
                    self.presentViewController(alertController, animated: true, completion: nil)
                    
                }
                else 
                {//版本是iOS7

                    let alertView = UIAlertView(title: "", message: "", delegate: self, cancelButtonTitle: "OK", otherButtonTitles: "Cancel")
                     //記得增加  UIAlertViewDelegate 在class 上面
                    //按鈕按下去的處理就要由 下面這個func 處理
                    //func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int)                
                    alertView.alertViewStyle = UIAlertViewStyle.PlainTextInput
                    alertView.tag = self.renamealert
                    self.renameAlertTextInput = alertView.textFieldAtIndex(0)
                    self.renameAlertTextInput.text = ""
                    alertView.show()
                    
                }

            }
        }

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 cwa1022 的頭像
    cwa1022

    整個城市都是我的開發館

    cwa1022 發表在 痞客邦 留言(0) 人氣()