使用代理将数据从xib传递到VC

时间:2018-09-22 09:04:59

标签: ios swift delegates iglistkit

我正在尝试将数据从xib向上两个级别传递到VC,以便可以导航到单独的视图。我确实在IGListKit节中获取了数据,但是由于某些原因,passDataFromSectionUp函数不会触发VC中的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 个答案:

答案 0 :(得分:0)

您的app.use(setDefaultResponse); app.use(router) 类中的delegate: PassSectionDelegate变量设置为nil,并且在您共享代码的情况下从未进行过更新。因此,在调用ExperiencesSectionController时,delegate?.passDataFromSectionUp(sectionController: self)变量将被标识为delegate,随后将不执行任何操作。