我有一个 UITableView
,其中包含两个用于用户放置信息的单元格。
第一个单元格:两个按钮“取消”和“完成”。
第二个单元格:用于用户类型信息的 UITextView
。
这在 iPhone 7、6s 中工作正常...但在 iPhone SE 和 5C 中屏幕不同。我使用了自动布局,并且在 Storyboard 中显示效果很好。
详细信息:我需要将 Height Constraint
设置为 TextView 才能正常工作。
区别如下图所示:
Storyboard:
TableView 的约束:
View Controller :
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!
}
最佳答案
关于ios - PrototypeCell 中的 UITextView 在两个 iPhone 模拟器中有不同的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52879031/