Transfer object from segue details disclosure button

How do I pass an object from the drop-down list of parts to the detail view controller? Are there any recommendations or quick fixes for this? Ideally, I want to create a method like this:

[self performSegueWithIdentifier:@"showDetail" sender:self passObject:object]; 

The reason is that “segue readiness” seems to be triggered only when pressed, when I click the cell in front of the part disclosure indicator. How to create a method like the one above to create the preparation effects below?

 if ([[segue identifier] isEqualToString:@"showDetail"]) { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; id object = [_objects objectAtIndex:indexPath.row]; [[segue destinationViewController] setDetailItem:object]; } 

I already tried to subclass UIStoryboardSegue like this, but ran into two problems.

 @implementation masterToDetail -(void)performSegueWithIdentifier:(NSString*)identifier sender:(id)sender passObject:(id)object{ [self.destinationViewController setDetailItem:object]; [self performSegueWithIdentifier:identifier sender:sender]; } -(void)performSegueWithIdentifier:(NSString*)identifier sender:(id)sender{ //What code should go here? Issue one } -(void)perform{ //Second issue, the compiler will crash and say I need to override perform. } 
+4
source share
3 answers

I fixed the problem by completely subclassing the segue idea. I removed the custom segue and made a push segue ( from tableviewcontrollre ) into the detail view controller. Then I created an instance variable NSIndexPath* _ipath; , and my code is as follows:

 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ _ipth = indexPath; [self performSegueWithIdentifier:@"showDetail" sender:self]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ NSLog(@"prepping"); if ([[segue identifier] isEqualToString:@"showDetail"]) { NSLog(@"in if"); id object = [_objects objectAtIndex:_ipth.row]; [[segue destinationViewController] setDetailItem:object]; } } 

This allows you to prepare for segue so that it works for the correct cell.

+4
source
  • open storyboard

  • select Master view Controller - Master

  • select Segue from UITableViewCell to view controller in detail - Detail

  • open attribute inspector

  • identifier → masterToDetail write

+1
source

You can simply right-click on the table view cell and then ctrl-drag from the accessories.

0
source

All Articles