Answer the question
In order to leave comments, you need to log in
How to transfer control by clicking on an object to the main controller?
There is a main controller ViewController - in it the main view
There is a TableView subclass: UIView
This view is created in the storyboard
At some point in time, many subviews are programmatically created in the TableView - of the CardView class - these are playing cards
each card is added to click processing
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[cView addGestureRecognizer:singleTap];
Answer the question
In order to leave comments, you need to log in
2 and 3 are one and the same. Method 1 (with notifications) is used if you need to notify several disparate objects. I think in your case the easiest way is to make a link to the controller in the CardView.
You have only one VC, we should write logic only in controllers. This VC needs to know about this tableView. Therefore, the delegate methods of tableView should be in this controller, those that are responsible for creating a cell, selecting a cell, and so on, which means that cardView will be created in the VC class, but then there are no questions about processing taps. So you've moved the logic to the View classes in vain.
If we want to separate the logic, then we need one more VC2, which will hold the tableView, will create cards, learn about their click. At the same time, the main VC1 will create it and immediately add the VC2 view to your own. That's when VC2 will delegate clicks on the cards to VC1.
There are a lot of examples of creating custom delegates, I won’t recommend a specific one, but they are easy to google.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question