Обновить метку UITableViewHeaderFooterView на tapGesture - PullRequest
0 голосов
/ 12 июня 2018

Я работаю над ячейкой Collapsable-Expandable Tableview , где я создал отдельный класс и xib для UITableViewHeaderFooterView и связал их друг с другом.Представление Xib содержит две метки: одну для Заголовок и одну для + или - , чтобы указать, что раздел свернут или развернут.Теперь в моем контроллере One of view у меня есть все необходимые методы tableview, и ниже приведен код для него.

var sections = [
    Section(Title: "Sec 1", Indicator : "-" , expanded : true, moview : ["Simba1","TaleSpin1"]),
    Section(Title: "Sec 2", Indicator : "+" ,expanded : false, moview : ["Simba2","TaleSpin2"]),
    Section(Title: "Sec 3", Indicator : "+" ,expanded : false, moview : ["Simba3","TaleSpin3"]),
    Section(Title: "Sec 4", Indicator : "+" ,expanded : false, moview : ["Simba4","TaleSpin4"])
]

var selectIndexPath: IndexPath!

override func viewDidLoad() {
    super.viewDidLoad();

    selectIndexPath = IndexPath(row: -1, section: -1)

    tableView.register(UINib(nibName: "HeaderView", bundle: nil), forHeaderFooterViewReuseIdentifier: "HeaderView");
}

override func numberOfSections(in tableView: UITableView) -> Int {
    return sections.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return sections[section].movie.count
}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 44
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if sections[indexPath.section].expanded {
        return 44
    } else {
        return 0
    }
}

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


override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    //let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "ExpandableHeader") as! ExpandableHeaderView;
    let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "HeaderView") as! HeaderView
    headerView.customInit(title: sections[section].Title , indicator: sections[section].Indicator , section: section, delegate: self)


    return headerView
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell")!;
    cell.textLabel?.text = sections[indexPath.section].movie[indexPath.row];

    return cell
}

func toggleSection(header: HeaderView, section: Int) {
    print("expanded: \(!sections[section].expanded)");
    sections[section].expanded = !sections[section].expanded
    sections[section].Indicator = "+"

    tableView.beginUpdates()
    for i in 0 ..< sections[section].movie.count {
        tableView.reloadRows(at: [IndexPath(row: i, section: section)], with: .automatic)
    }
    tableView.endUpdates()
}

Я хочу изменить метку + или - в зависимости от того, свернут ли разделили расширенный пользовательский кран.Я попытался добавить sections[section].Indicator = "+" эту строку в toggleSection функцию, но безрезультатно.

Любая помощь будет оценена.

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