Передача данных с использованием делегатов из Xib в VC

Я пытаюсь передать данные на два уровня из XIB в VC, чтобы я мог перейти к отдельному представлению. Я получаю данные в разделе IGListKit, но по какой-то причине passDataFromSectionUp функция не вызывает print("like") функция в ВК.

VC

class MainViewController: UIViewController, PassSectionDelegate {

func passDataFromSectionUp(sectionController: ExperiencesSectionController) {
    print("Like"); //Doesn't trigger
}

Раздел IGListKit

protocol PassSectionDelegate: class {
  func passDataFromSectionUp(sectionController: ExperiencesSectionController);
}

class ExperiencesSectionController: ListSectionController, UpdateDataDelegate {

weak var delegate: PassSectionDelegate? = nil;

func passUpdateData(data: String) {
    print(data) //Data gets received
    delegate?.passDataFromSectionUp(sectionController: self);
}

...

if let cell = cell as? CarouselControlCell {
        cell.delegate = self;
    }

XIB

protocol UpdateDataDelegate: class {
  func passUpdateData(data: String);
}

class CarouselControlCell: UICollectionViewCell {

weak var delegate: UpdateDataDelegate? = nil

@IBAction func addUpdate(_ sender: Any) {
    delegate?.passUpdateData(data: "teeest");
}

1 ответ

Решение

delegate: PassSectionDelegate переменная в вашем ExperiencesSectionController Для класса установлено значение nil, и он никогда не обновлялся с учетом кода, которым вы поделились. При звонке delegate?.passDataFromSectionUp(sectionController: self), delegate Таким образом, переменная будет обозначена как nil и, следовательно, ничего не будет выполнено.

Другие вопросы по тегам