How to stop scrolling in uitableview while editing uitextfield

Solution . When I use super. viewWillAppear(true), then my view looks perfect with the keyboard, but here, automatic scrolling creates an editing problem UITextField.

In mine, UITableViewI use two cellfor details, and the other for the footer buttonSign UP

View image before KeyBoard

BEFORE CELLS

View image after KeyBoard

After keyboard

Here is the code for the footer

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    self.navigationController?.isNavigationBarHidden = false
    getTimeZone()
    spinnerInitialization()
    let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
    imageView.contentMode = .scaleAspectFit
    let image = UIImage(named: "Home_Logo2")
    imageView.image = image
    navTitle.titleView = UIImageView(image: image)
    hideKeyboardWhenTappedAround()
}

Code for the footer where you can see the registration button

    override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let  footerCell = tableView.dequeueReusableCell(withIdentifier: "footer") as! CreateAccountTableViewCell
    let indexPath = IndexPath(row: 0, section: 0)
    let  cell = tableView.cellForRow(at: indexPath) as! CreateAccountTableViewCell
    footerCell.signupButtonClick = {
        if cell.cmpName.text!.isEmpty || cell.email.text!.isEmpty || cell.firstName.text!.isEmpty || cell.lastName.text!.isEmpty || cell.password.text!.isEmpty || cell.cnfirmPassword.text!.isEmpty  {
            let dialog = UIAlertController(title: "All Field Required", message: "Please check, All field are required", preferredStyle: UIAlertControllerStyle.alert);
            let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default){(ACTION) in
                return
            }
            dialog.addAction(okAction);
            DispatchQueue.main.async(execute: {
                UIApplication.shared.keyWindow?.rootViewController?.present(dialog, animated: true, completion: nil)
            })
        }
        else {
            if cell.password.text! != cell.cnfirmPassword.text! {
                let dialog = UIAlertController(title: "Confirm Password does not matched.", message: "", preferredStyle: UIAlertControllerStyle.alert);
                let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default){(ACTION) in
                    return
                }
                dialog.addAction(okAction);
                DispatchQueue.main.async(execute: {
                    UIApplication.shared.keyWindow?.rootViewController?.present(dialog, animated: true, completion: nil)
                })
            }
            let postString = "cmpname=\(cell.cmpName.text!)&email=\(cell.email.text!)&firstName=\(cell.firstName.text!)&lastName=\(cell.lastName.text!)&password=\(cell.password.text!)&cnfirmPassword=\(cell.cnfirmPassword.text!)&token=\("afdg2015")&signUpFrom=\("IOS")&timezone=\(cell.timezonePickerView.selectedRow(inComponent: 0))&currentPlanId=\(4)"
            self.registerMe(postString: postString, password: cell.password.text! )
        }
    }
    return footerCell
}

Code for detailed viewing Where you can see Edit text

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "detailsCell", for: indexPath) as! CreateAccountTableViewCell
    DispatchQueue.main.async(execute: {
        cell.timezonePickerView.reloadAllComponents()
        cell.timezonePickerView.selectRow(self.idSelect, inComponent: 0, animated: false)
        cell.cmpName.underlined()
        cell.email.underlined()
        cell.firstName.underlined()
        cell.lastName.underlined()
        cell.password.underlined()
        cell.cnfirmPassword.underlined()
        cell.cmpName.delegate = self
        cell.email.delegate = self
        cell.firstName.delegate = self
        cell.lastName.delegate = self
        cell.password.delegate = self
        cell.cnfirmPassword.delegate = self
    })
    cell.selectionStyle = .none
    return cell
}

, UITextField, . , , , .

...

+4
1
  • UIViewController UITableViewController
  • UITableView .
  • SIGN UP , .
  • WillShow/DidShow/WillHide/DidHide . , .

.

0

Source: https://habr.com/ru/post/1674089/


All Articles