Не удается найти причину, по которой tableViewCell не редактируется и текст по умолчанию не отображается - PullRequest
0 голосов
/ 04 ноября 2018

Извините за невежественный вопрос, но я пытаюсь следовать учебнику appdev моей школы, и я наткнулся на ошибку, когда пытаюсь создать редактируемые ячейки табличного представления, но не отображаются ни текст по умолчанию, ни возможность редактирования. Я проверил в пользовательском классе TableViewCell и там есть выход TextView. Любая помощь будет высоко ценится: 3

import UIKit

class AddVerbViewController: UIViewController, UITableViewDelegate, 
UITableViewDataSource{

var isPickerViewOpened : Bool = false

@IBOutlet weak var TableView: UITableView!

@IBAction func DoneButtonTapped(_ sender: Any) {
    dismiss(animated: true, completion: nil)
}

@IBAction func ClearButtonTapped(_ sender: Any) {
    dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
    super.viewDidLoad()

    TableView.delegate = self
    TableView.dataSource = self

    print("yes")
    // Do any additional setup after loading the view.
}
//MARK: - Table View Methods
func numberOfSections(in tableView: UITableView) -> Int {
    print("number of sections : 2")
    return 2

}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if (section == 0){
        return 2
    } else {
        return 2
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "AddVerbCell", for: indexPath)as! AddVerbTableViewCell
    cell.TextView.textContainer.maximumNumberOfLines = 1
    cell.TextView.textContainer.lineBreakMode = .byTruncatingTail
    cell.PickerView.isHidden = true

    if (indexPath.section == 0) {
        cell.TextView.isEditable = true
        cell.TextView.textColor = UIColor.gray
        cell.TextView.isScrollEnabled = false
        if (indexPath.row == 0){
            print("cell Name")
            cell.TextView.text = "Name"
        } else {
            cell.TextView.text = "TeForm"
        }
    } else {
        if (indexPath.row == 0) {
            cell.TextView.isEditable = false
            cell.TextView.isSelectable = false
            cell.TextView.textColor = UIColor.black
            cell.TextView.text = "PotentialForm"
        } else {
            cell.TextView.isHidden = true
            cell.PickerView.isHidden = false
        }
    }
    return cell
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 20
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if (indexPath.section == 0) {
        return 50
    } else {
        if (indexPath.row == 0){
            return 50
        } else {
           return 100
        }
    }
    }
/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destination.
    // Pass the selected object to the new view controller.
}
*/

}

1 Ответ

0 голосов
/ 04 ноября 2018

Я на самом деле понял это. Поэтому мне нужно было добавить cell.TextView.isUserInteractionEnabled = true в соответствующие области. Теперь это работает! Извините за беспокойство всех

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...