簡體   English   中英

如何在編輯uitextfield時停止在uitableview中滾動

[英]how to stop scrolling in uitableview while editing uitextfield

堆棧溢出解決方案 當我使用super. viewWillAppear(true) super. viewWillAppear(true)然后我的視圖看起來很完美的鍵盤,但這里自動滾動創建編輯UITextField問題。

在我的UITableView我使用兩個cell來獲取詳細信息,另一個用於頁腳按鈕Sign UP

在KeyBoard之前查看圖像

在KeyBoard之前

在KeyBoard之后查看圖像

KeyBoard之后

這里代碼為頁腳視圖

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()
}

代碼頁腳,您可以在其中看到注冊按鈕

    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
}

代碼詳細信息視圖您可以在哪里看到編輯文本

 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 ,視圖會自動滾動到任意位置。 我希望滾動應該在用戶滾動時工作,其他滾動應該停止。

我如何才能完成這項任務......

  1. 使用常規的UIViewController而不是UITableViewController
  2. 將您的UITableView添加為主視圖的子視圖。
  3. 添加您的SIGN UP鍵為主要景觀的另一個子視圖,限制在主視圖的底部。
  4. 根據需要添加鍵盤WillShow / DidShow / WillHide / DidHide通知的處理。 當鍵盤滑入或滑出視圖時,同時為注冊按鈕視圖的位置設置更改動畫。

這將禁用表視圖的自動滾動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM