Stack Overflow Solution。当我使用
super. viewWillAppear(true)
时,我的视图看起来很完美,但是这里自动滚动会导致编辑UITextField
时出现问题。
在我的UITableView
我使用两个cell
一个用于详细信息而另一个用于页脚按钮Sign UP
在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))¤tPlanId=\(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 :(得分:0)
UIViewController
代替UITableViewController
UITableView
添加为主视图的子视图。SIGN UP
按钮作为主视图的另一个子视图,约束在主视图的底部。这将禁用表格视图的自动滚动。