2017-04-05 13 views
4

Stack Overflow Solutionsuper. viewWillAppear(true)を使用すると、私のビューはキーボードで完璧に見えますが、ここでは自動スクロールでUITextFieldの編集で問題が発生します。私UITableViewuitextfieldの編集中にuitableviewでスクロールを止める方法

私は、キーボードの後、キーボード

BEFORE KeyBoard

見るイメージの前にSign UP

フッターボタンの表示イメージを2 cell詳細については、1と別のものを使用しています

After KeyBoard

ここでフッターを表示あなたがサインアップログインボタン

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

コードについてはフッターのコード私はUITextField上の任意のランダムな位置に表示オートスクロールをクリックすると、あなたはテキスト編集ここ

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 
} 

を見ることができる詳細ビューのために210

コード。私は望むスクロールは、ユーザーが他の賢明なスクロールを停止する必要がありますスクロールするときに仕事をする必要があります。私はそのタスクを達成するにはどうすればよい

...

+0

これを正しく行うには、キーボードが表示されたとき(つまり、texfieldがタップされている)、スクロールを無効にすることをお探しですか? –

+0

'UITableViewController'を使わずに' UIViewController'のビューにテーブルを埋め込みましたか?この場合、テーブルビューは自動的にスクロールされません。 – DonMag

+0

@AhmadFはいいいえ 'テキストフィールドでタップしたときに自動スクロールをオフにしたい' –

答えて

0
  1. 代わりUITableViewController
  2. の定期UIViewControllerを使用して、メインビューのサブビューとしてあなたUITableViewを追加します。
  3. SIGN UPボタンをメインビューの別のサブビューとして追加し、メインビューの下部に拘束します。
  4. キーボードWillShow/DidShow/WillHide/DidHide通知の処理を必要に応じて追加します。キーボードがスライドして表示されたり表示されなくなったりすると、サインアップボタンの表示位置の変更を同時にアニメーション表示できます。

これにより、テーブルビューの自動スクロールが無効になります。

関連する問題