Representation of view controllers on separate ... - sometimes

Like other iOS8 users, I get a warning:

Presenting view controllers on detached view controllers is discouraged <EditItineraryViewController: 0x7ca56e00>. 

This is caused by the following code:

 - (void)editActivityDetailsForIndexPath:(NSIndexPath *)indexPath { NSPredicate *predicateForDisplay = [[NSPredicate alloc] init]; switch (indexPath.section) { case kIncompleteActivitiesSection: predicateForDisplay = _predIncomplete; break; case kCompleteActivitiesSection: predicateForDisplay = _predComplete; break; default: break; } NSString *theActivityName = [[NSString alloc] init]; theActivityName = [[[_activitiesArray filteredArrayUsingPredicate:predicateForDisplay] objectAtIndex:indexPath.row] activityName]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ActivityDetailViewController *activityDetailVC = [storyboard instantiateViewControllerWithIdentifier:@"ActivityDetailView"]; activityDetailVC.modalPresentationStyle = UIModalPresentationFormSheet; activityDetailVC.delegate = self; // send the activity to the view activityDetailVC.theActivity = [[_activitiesArray filteredArrayUsingPredicate:predicateForDisplay] objectAtIndex:indexPath.row]; // configure the look of the view _activityDetailsPopover = [[UIPopoverController alloc] initWithContentViewController:activityDetailVC]; _activityDetailsPopover.delegate = self; ItineraryCell *cell = (ItineraryCell *)[self.itineraryTableView cellForRowAtIndexPath:indexPath]; activityDetailVC.contentView.backgroundColor = [UIColor whiteColor]; activityDetailVC.navigationBar.barTintColor = _colorSchemeLightColor; activityDetailVC.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:_colorSchemeColor}; activityDetailVC.saveButton.tintColor = _colorSchemeColor; activityDetailVC.cancelButton.tintColor = _colorSchemeColor; activityDetailVC.labelB.textColor = _colorSchemeColor; activityDetailVC.labelM.textColor = _colorSchemeColor; activityDetailVC.activityTitle.textColor = _colorSchemeColor; activityDetailVC.activityTitle.font = [UIFont boldSystemFontOfSize:17.0]; // present the view [_activityDetailsPopover presentPopoverFromRect:cell.cellDetailsButton.frame inView:cell.cellDetailsButton.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } 

This is an iPad application, and in this case, the popover is presented in such a way that its small pointer points to the "i" icon, which is located in the tableview cell as a table.

This works in three other places in my application without causing a warning at all. But for some reason, with this implementation, this raises a warning. The strange thing is that this was the first place in my application. I used this tool to represent a popover from a tableview cell, and other instances are just copies of this code!

Any ideas that I can look at to find out where the hierarchy is distorted? Is this related to how the tableview cell is generated, and then this popover is presented on top of it, or should it do strictly with the popover itself? Or it may be related to the table. I donโ€™t even know where to start looking.

Many thanks!

+5
source share
1 answer

I worked on this issue by presenting a popover from a view controller that represents a tableView (in my case, a collection view). The problem arises when you present from a cell. I assume that any cell is considered an โ€œindependent view controller,โ€ so the view from them will give you this error and will not receive rotation events, which, in turn, will not use the popoverPresentationController:willRepositionPopoverToRect:inView: .

+2
source

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


All Articles