【发布时间】:2017-10-15 04:12:10
【问题描述】:
我有一个带有几个 UITextField、一个 UILabel 和一个 UITextView 的可扩展 tableViewCell。当 tableView 展开标签消失并且 UITextFields 和 UITextView 出现。在两个 UITextFields 中都会出现光标,但在 UITextView 中没有光标出现。我已经尝试更改色调颜色并且没有任何东西,但是当我选择文本(确实出现)时,文本以色调颜色突出显示并且可见。我也试过改变框架,但没有奏效。此外,我现在将其设置为常规 UITextView,除了框架之外没有任何属性的更改。 textView 是使用 UITableViewCell 类以编程方式设置的,除了光标之外,一切似乎都正常工作。
这是我设置 UITextView 的方式:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! StudentTableViewCell
cell.infoView.frame = CGRect(x: 23, y: 207, width: cell.frame.width - 36, height: cell.frame.height - 155)
cell.infoView.delegate = self
cell.infoView.text = classes[indexPath.row].info
cell.infoView.layer.cornerRadius = 5
cell.infoView.layer.masksToBounds = true
cell.placeholderField.frame = CGRect(x: 32, y: 92, width: self.view.frame.width - 38, height: 45)
if cell.infoView.text!.replacingOccurrences(of: " ", with: "") == "" {
cell.placeholderField.placeholder = "Description"
} else {
cell.placeholderField.placeholder = ""
}
cell.placeholderField.backgroundColor = UIColor.clear
cell.nameField.frame = CGRect(x: 23, y: 3, width: cell.frame.width - 70, height: 44)
cell.nameField.text = classes[indexPath.row].name
cell.nameField.delegate = self
cell.nameField.layer.cornerRadius = 5
cell.nameField.layer.masksToBounds = true
cell.nameField.borderStyle = .roundedRect
cell.teacherField.frame = CGRect(x: 23, y: 50, width: cell.frame.width - 36, height: 44)
cell.teacherField.text = classes[indexPath.row].teacher.name
cell.teacherField.delegate = self
cell.teacherField.layer.cornerRadius = 5
cell.teacherField.layer.masksToBounds = true
cell.teacherField.borderStyle = .roundedRect
cell.editButton.frame = CGRect(x: self.view.frame.width - 60, y: 15, width: 70, height: 20)
cell.editButton.addTarget(self, action: #selector(self.editInfoView), for: .touchUpInside)
cell.editButton.setTitle(cell.editButton.title(for: .normal) ?? "Edit", for: .normal)
cell.contentView.addSubview(cell.nameField)
cell.contentView.addSubview(cell.teacherField)
cell.contentView.addSubview(cell.infoView)
cell.contentView.addSubview(cell.editButton)
cell.contentView.addSubview(cell.placeholderField)
cell.textLabel?.text = classes[indexPath.row].name
cell.detailTextLabel?.text = classes[indexPath.row].teacher.name
return cell
}
这是类定义:
class StudentTableViewCell: UITableViewCell {
var infoView = UITextView()
var placeholderField = UITextField()
var nameField = UITextField()
var teacherField = UITextField()
var editButton = UIButton()
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
有谁知道为什么光标没有出现?
提前感谢您的帮助。
以下是已选中光标的调试层次结构中的照片: Photo from the side
光标前面的视图是placeholderField,并没有阻塞光标,因为光标在placeholderField下方时仍然没有出现。
【问题讨论】:
标签: ios uitextview caret