【发布时间】:2018-10-18 16:58:49
【问题描述】:
我有一个UITableView,有两个单元格用于用户输入信息。
第一个单元格:“取消”和“完成”两个按钮。
第二个单元格:UITextView 用于用户类型信息。
这在 iPhone 7、6s 中运行良好……但在 iPhone SE 和 5C 中屏幕不同。我使用了自动布局,在情节提要中看起来效果很好。
详细信息:我需要将 Height Constraint 设置为 TextView 才能工作。
如下图所示:
故事板:
TableView 的约束:
视图控制器:
class LiberarViewController : UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate {
@IBOutlet weak var tableViewForm: UITableView!
var callback : ((String)-> ())?
override func viewDidLoad() {
tableViewForm.dataSource = self
tableViewForm.delegate = self
// tableViewForm.tableFooterView = UIView()
}
@objc func cancelar(_ sender: Any) {
self.dismiss(animated: true, completion: {})
}
@objc func finalizar(_ sender: Any) {
self.dismiss(animated: true, completion: {})
}
func textViewDidEndEditing(_ textView: UITextView) {
print("End edigint: \(textView.text!)")
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 1 {
return "Digite a justificativa: "
}
return nil
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "CellBotoesLiberar") as! CellBotoesLiberar
cell.selectionStyle = .none
cell.btCancelar.addTarget(self, action: #selector(cancelar), for: .touchUpInside)
cell.btFinalizar.addTarget(self, action: #selector(finalizar), for: .touchUpInside)
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "CellJustificativaLiberar") as! CellJustificativaLiberar
cell.txtViewJustificativa.delegate = self
return cell
default: return UITableViewCell()
}
}
}
class CellJustificativaLiberar : UITableViewCell {
@IBOutlet weak var txtViewJustificativa: UITextView!
}
class CellBotoesLiberar : UITableViewCell {
@IBOutlet weak var btFinalizar: UIButton!
@IBOutlet weak var btCancelar: UIButton!
}
【问题讨论】:
-
你为 TableView 设置了什么约束?
-
我已经编辑了.....
标签: ios swift xcode uitableview autolayout