// // ModUserInfoViewController.swift // CommonFrame // // Created by Virgil on 2019/1/28. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class ModUserInfoViewController: BaseViewController, UITextFieldDelegate { @IBOutlet weak var txtName: UITextField! ///0修改昵称 1:修改签名 var typeTitle = "昵称" var type = 0 override func viewDidLoad() { super.viewDidLoad() initNavLeftBackButton() if type == 0 { typeTitle = "昵称" txtName.text = CommonValue.getUserNickName() } else { typeTitle = "签名" txtName.text = "" } self.title = "设置\(typeTitle)" txtName.placeholder = "请输入\(typeTitle)" txtName.setContentMarginLeft(leftWidth: 22) initNavRightButtonForTitle(title: "保存", color: CommonUntils.getUIColorFromRGB(rgbValue: 0xffffff, alpha: 1.0)) txtName.delegate = self } override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) { txtName.resignFirstResponder() } func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { // if txtName.text!.length() > 20 { // return false // } else { return true // } } override func btnRightMenuClick() { saveData() } // MARK: =============加载数据=============== func saveData() { if txtName.text!.length() < 1 { SVProgressHUD.showError(withStatus: "请输入\(typeTitle)!") return } // if txtName.text!.length() > 10 { // txtName.attributedText = CommonViewUntils.getAttributedString(str: txtName.text!, left: [10, txtName.text!.length()], color: [CommonUntils.getUIColorFromRGB(rgbValue: 0x000000, alpha: 1.0), UIColor.red]) // SVProgressHUD.showError(withStatus: "\(typeTitle)超过长度,最多可输入10个字符") // return // } let url = RequestURL.editUser let params = NSMutableDictionary() if type == 0 { params.setValue(txtName.text!, forKey: "nickName") } else { params.setValue(txtName.text!, forKey: "signature") } params.setValue(CommonValue.getUserId(), forKey: "userId") submitData(url: url, params: params, tag: 1001) } override func returnData(tag: Int) { if tag == 1001 { appDelegate.reloadUserInfo() SVProgressHUD.showSuccess(withStatus: "修改成功") handleBack() } } override func returnError(tag: Int, type: String) { if tag == 1001 { } } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "ModUserInfoViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ }