Answer the question
In order to leave comments, you need to log in
How to pass data from UITableViewCell to UIViewController?
Good afternoon))
The problem is this: there is a cell in the TableView that contains one UIImageView, one Label and a button. By clicking on the button, a transition is made to another UIViewController.
Question: how to pass the data that is in the cell to the UIViewController when switching to it after clicking the button?
I just can’t figure it out, I tried somehow to transfer it from the cell class through Segue, it doesn’t work.
Yes, the cell has its own class.
Answer the question
In order to leave comments, you need to log in
Analyze your architecture, if you need to receive data from a cell - this is, unfortunately, an architectural error. Cells are intended only for displaying data from the data source (actually, the datasouce of the collection view). If, after "clicking" on the button, or segue occurs, then the cell index can be determined:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
//не забыть проверить, кто такой sender
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
//получить данные из datasource
}
Without seeing your code, I guess you should try some more work with segue
Dear Ray posted a good tutorial on storyboards
www.raywenderlich.com/50310/storyboards-tutorial-i...
I haven't worked much with storyboards, more old fashioned with xib' ami
but the transmission should be as in Ray's example
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"PickGame"]) {
GamePickerViewController *gamePickerViewController = segue.destinationViewController;
gamePickerViewController.delegate = self;
gamePickerViewController.game = _game;
}
}
Usually this is done through delegation
Here is an
example
stackoverflow.com/questions/8062572/adding-a-deleg ... 4910323/delegate-from-...
And pass the element number through the button tag. Although it will turn out perverted ...
Another option is blocks, if you don’t like delegation
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question