2017-10-15 4 views
0

私は、UITextFields、UILabel、およびUITextViewの2つを持つexpandable tableViewCellを持っています。 tableViewが展開されると、ラベルが消え、UITextFieldsとUITextViewが表示されます。どちらのUITextFieldsでもカーソルは表示されますが、UITextViewではカーソルが表示されません。色合いを変更しようとしましたが、何も表示されませんでしたが、テキストを選択すると、色合いが強調されて表示されます。私もフレームを変更しようとしましたが、うまくいきませんでした。また、フレーム以外のプロパティに変更を加えずに、通常のUITextViewとして設定することもできます。 textViewは、プログラムでUITableViewCellクラスを使用してセットアップされ、すべてが動作するように見えますが、カーソルです。ここでカーソルがUITextViewに表示されないiOS

は、私は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

Photo from the front

カーソルの前のビューがplaceholderFieldで、カーソルがまだないので、カーソルがブロックされていない。ここで

は、カーソル選択とデバッグの階層からの写真ですplaceholderFieldの下にあるときに表示されます。

答えて

1

まず第一に、あなたのコードがどのようにあなたのために働いているのか分からず、それをコンパイルせずに私はいくつかの主要な問題を見ることができます。

  • ここでCellcellForRowAt indexPathに戻していますか?
  • cell.teacherNameFieldStudentTableViewCell

そして率直に話すには存在しない、これらの事は難しくありません、彼らは方法あなただけのだけにして(それぞれ、すべての可能なアプローチ)コードを書く前に、それをシンプルに保つと考えて、コードにしようとしていますベストプラクティスを達成します。

あなたの質問に戻ってきましたが、私はあなたのコードベースで試してみました。重複しているので、これを行うことができません。あなたはそれを解決できる最高の人です。

使用Debug View Hierarchy

enter image description here

そして、あなたはあなたの画面上にそれぞれ、すべてのランタイムビュー層を見ることができます。

enter image description here

+0

私のコードは申し訳ありません。私はそれらのプロパティが物事を変更していたかどうかを確認するために多くのコメントをして、私は誤ってその中にあることを意図した行を削除しました。私は今までのすべてのもので自分のコードを更新しました。また、実際にどのようにカーソルをDebug View Hierarchyに表示しているか2つの写真を追加しました。私はまた、カーソルの説明を印刷し、何らかの理由でアルファが0です。アルファを0から1に変更して見えるようにする方法はありますか?もう一度助けてくれてありがとう。私が他のことをプログラムするとき、その提案を心に留めておく。 –

関連する問題