巴布顿正在离开这个位置

时间:2017-06-28 04:14:58

标签: ios swift uinavigationbar uibarbuttonitem uialertcontroller

在我提出uialertcontroller之前,一切都很好。当我呈现它时,barbutton正从他们的位置向下移动。

Before presenting,everything was fine with barbuttons

When i present an alert,you can see the UIBarButtonItems are off their position

创建barbuttonitem s ::

的代码
let editBtn:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: IMAGE_EDIT_ICON), style: .plain, target: self, action: #selector(handleEditAction))
self.navigationItem.rightBarButtonItem = editBtn

如下所示展示UIAlertControlelr

let alertController = UIAlertController(title: "Reset Password", message: "Please enter current password and create new password", preferredStyle: .alert)
   let okAction =  UIAlertAction(title: "Confirm", style: .default, handler: { [weak alertController] (_) in
   })


let cancelAction = UIAlertAction(title: "Cancel", style: .default) { (_) in }


alertController.addAction(cancelAction)
alertController.addAction(okAction)



okAction.isEnabled = false


alertController.addTextField { (textField) in
    textField.placeholder = "Current Password"
    }


}
alertController.addTextField { (textField) in
    textField.placeholder = "New Password"
    }


}
alertController.addTextField { (textField) in
    textField.placeholder = "Confirm Password"
    textField.isSecureTextEntry = true
    NotificationCenter.default.addObserver(forName: NSNotification.Name.UITextFieldTextDidChange, object:textField,
                                           queue: OperationQueue.main) {
                                            (notification) -> Void in
                                            self.validateResetPassword(alertController: alertController,okAction: okAction)
    }



}

self.present(alertController, animated: true, completion: nil)

有人可以帮我解决这个问题。 提前致谢

2 个答案:

答案 0 :(得分:1)

如下所示更换栏按钮:

let barButton =    UIBarButtonItem(image: UIImage(named: "imageName"), style: .plain, target: self, action: #selector(self.YourSelectorTarget))

答案 1 :(得分:0)

我建议您使用 Interface Builder (IB)来设置UIBarButtonItems。 您也可以通过IB和代码设置图像。

  1. 在Interface Builder上设置UIBarButtonItem
  2. 使用代码:
  3. -

    let editBtn:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: IMAGE_EDIT_ICON), style: .plain, target: self, action:#selector(handleEditAction)) self.navigationItem.rightBarButtonItem = editBtn