2017-04-05 99 views
4

Stack Overflow Solution。當我使用super. viewWillAppear(true)時,我的視圖與鍵盤看起來很完美,但在這裏自動滾動會產生編輯UITextField的問題。如何在編輯uitextfield時停止在uitableview中滾動

在我UITableView我正在使用兩個cell一個細節,另一個用於頁腳按鈕Sign UP

查看圖像之前鍵盤

BEFORE KeyBoard

查看圖片上鍵盤後

After 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單擊視圖自動滾動。我想滾動應該工作,當用戶做滾動其他明智的滾動應停止。

我怎樣才能實現這一任務......

+0

爲了讓它正確無誤,您在尋找禁用鍵盤顯示時的滾動功能(即,texfield已被點擊)是什麼? –

+0

您是否嘗試過在'UIViewController'的視圖中嵌入表而不是使用'UITableViewController'?我*相信*在這種情況下,表格視圖不再自動滾動。 – DonMag

+0

@AhmadF是的,你是對的'我想在自動滾動時在文本框上點擊' –

回答

0
  1. 使用普通UIViewController代替UITableViewController
  2. 添加您UITableView作爲主視圖的一個子視圖。
  3. 將您的SIGN UP按鈕添加爲主視圖的另一個子視圖,限制在主視圖的底部。
  4. 根據需要添加鍵盤WillShow/DidShow/WillHide/DidHide通知的處理。當鍵盤滑入或滑出視圖時,同時動態更改註冊按鈕視圖的位置。

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

相關問題