D
D
Darkness2020-02-29 15:49:05
Swift
Darkness, 2020-02-29 15:49:05

What is wrong with delegation?

Question:
I need to do a function delegation, but I can't figure out where I went wrong or what knowledge I lack.
I have a "master file" (boss):

protocol MainViewControllerDelegate {
    func openedSideBar()
}
// ниже в этом же файле
var delegate: MainViewControllerDelegate?
// еще ниже
delegate?.openedSideBar()

There is also a class responsible for the xib file
. In it:
var mainViewControllerDelegate = MainViewController()

In awakeFromNib:
mainViewControllerDelegate.delegate = self

And, accordingly, the function itself:
extension MainCellCollectionView: MainViewControllerDelegate {
    func openedSideBar() {
        print("1")
    }
}

This print does not work... What was pierced in?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2020-02-29
@AntonBrock

You kind of twisted everything.
I'll try to answer abstractly:
Object Senior owns the object Junior.
Object Major, satisfies the Delegate Minor protocol.
The Major object sets itself as a delegate to the Minor object. (of type mladshiy.delegate = self)
When the junior has a sidebar, he should call the appropriate delegate method (of type delegate.openedSideBar())
I hope this will give you an understanding of what you lack in knowledge.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question