ios - PrototypeCell 中的 UITextView 在两个 iPhone 模拟器中有不同的行为

标签 ios swift xcode uitableview autolayout

我有一个 UITableView,其中包含两个用于用户放置信息的单元格。

第一个单元格:两个按钮“取消”和“完成”。 第二个单元格:用于用户类型信息的 UITextView

这在 iPhone 7、6s 中工作正常...但在 iPhone SE 和 5C 中屏幕不同。我使用了自动布局,并且在 Storyboard 中显示效果很好。 详细信息:我需要将 Height Constraint 设置为 TextView 才能正常工作。

区别如下图所示:

enter image description here

Storyboard:

enter image description here

TableView 的约束:

enter image description here

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!
}

最佳答案

您的 TableView 对安全区域的最高约束导致了问题。添加以下约束:

  1. 水平和垂直居中于父 View 。
  2. 固定高度和固定宽度/前导和尾随到 Superview。

希望这对你有用。

enter image description here

enter image description here

关于ios - PrototypeCell 中的 UITextView 在两个 iPhone 模拟器中有不同的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52879031/

相关文章:

ios - 将图像从库加载到 UICollection View 。应用程序不断崩溃

javascript - 在 Cordova 插件中从 Objective C 执行 Javascript

ios - 从 IOS 中的 UItableView 中的自定义单元格继续

ios - 外设写入值: forCharacteristic: type: return null error and value

ios - 创建用于单元测试的模拟数据对象

ios - Xcode 脚本的相对路径

xcode - UITapGestureRecognizer 与 didSelectRowAtIndexPath 冲突

ios - Swift - GMSMarker 沿着 GMSPath 的 CLCoords 数组移动(适用于 iOS 的 Google map SDK)

ios - 包含某些字符的字符串导致 UITextView 过早换行

xcode - 如何为我的 Interface Builder 对象分配不同的 z 顺序?