How do I know which segue is called a destination in unwind mode?

I have a spread in my WishlistVC (VC, which lists all wish lists). Now this VC allows the user to click on the wish list and, if it is empty, call the EditWishlistItems VC so that you can choose which items to place inside this wish list. WishlistVC also has another button that allows the user to create a new wish list, and then calls EditWishlistItems so that the user can add items to the new wish list. Both of these parameters apply to the same VC.

When I relax, I want to know who called VC EditWishlistItems , i.e. which session I performed while moving forward in my unwind session. If it is from the addItemsToWishlist modal segment, then I want to add the wish list to Core Data, and if it is from the EditWishlistItems modal segue, I want to edit the wish list items on the CD.

Any way to find out this information when I relax?

+4
source share
2 answers

THE_DOM's answer is good, but I somehow fixed my problem.

To find out if we need to change modally, we check to see if there are any elements in our delegate method in our wish list. If not, we will say that to happen. If it has elements, then push segue will be automatically called instead of it (configured in IB).

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Wishlist *wishlist = [self.fetchedResultsController objectAtIndexPath:indexPath]; if([wishlist.items count] == 0) { // execute our segue [self performSegueWithIdentifier:@"editWishlistItems" sender:self]; } } 

In our prepareForSegue we set BOOL to indicate to the user who clicked on the empty wish list (this is at our VC destination).

 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; ... // other segues if([segue.identifier isEqualToString:@"editWishlistItems"]) { UINavigationController *navigationVC = (UINavigationController *)segue.destinationViewController; ManageWishlistItemCDTVC *manageWishlistItemVC = (ManageWishlistItemCDTVC *)navigationVC.topViewController; manageWishlistItemVC.tappedOnEmptyWishlist = YES; manageWishlistItemVC.wishlist = [self.fetchedResultsController objectAtIndexPath:indexPath]; } } 

And then when we relax, we check to see if there is BOOL YES or NO .

 - (IBAction)saveWishlistItem:(UIStoryboardSegue *)segue { ManageWishlistItemCDTVC *manageWishlistItemVC = (ManageWishlistItemCDTVC *)segue.sourceViewController; // check to see if we came from edit segue or add segue if(manageWishlistItemVC.tappedOnEmptyWishlist) { // edit segue // saved edited wishlist } else { // add segue if([manageWishlistItemVC.selectedItems count] > 0) { // save new wishlist } } 
+1
source

I would do this by adding a property

 @property (nonatomic, strong) NSString *recentSegue; 

and then creating

 -(void)addItemsToWishList:{ //business logic self.recentSegue = @"addItems"; [self performSegueWithIdentifier:@"EditWishlistItems" sender:self]; } -(void)editWishListItems:{ //business logic self.recentSegue = @"editItems"; [self performSegueWithIdentifier:@"EditWishlistItems" sender:self]; } 

Then bind your buttons to these methods, rather than doing segues directly

and finally

 -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if(self.recentSegue){ if(self.recentSegue isEqualToString:@"addItems") { //do Whatever } else if(self.recentSegue isEqualToString:@"editItems") { //do whatever else } self.recentSegue = nil; } } 

While this should work, another way that might be better depending on your design is to let DirectWishListItems directly handle the interaction with coredata.

+6
source

Source: https://habr.com/ru/post/1483453/


All Articles