I'm maintaining an old code based on xib files. Everything worked fine, but recently, the back button of the navigation bar in a popover is no longer responding. I changed from using a UIPopoverController to presenting the navigation controller with UIModalPresentationPopover style but nothing changed. Here's what I'm doing:
navController = [[UINavigationController alloc] initWithRootViewController:instrusRootVC];
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.preferredContentSize = CGSizeMake(400.0, 600.0);
navController.popoverPresentationController.sourceView = self.view;
navController.popoverPresentationController.sourceRect = sender.frame;
navController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
navController.popoverPresentationController.delegate = self;
[self presentViewController:navController animated:YES completion:nil];
where instrusRootVC is a table view controller initialized with initWithNibName
in instrusRootVC, I then call
[[self navigationController] pushViewController:secondVC animated:YES];
where secondVC is a new table view controller initialized with initWithNibName
Everything works fine except that the back button of the navigation bar does not respond.
(If I call
[[self navigationController] popViewControllerAnimated:YES];
somewhere in secondVC, it works fine.)
What am I doing wrong?
The full code is too long to go in comments, so here it is:
UINavigationController *navController;
if (APPTYPE == kTypeMultiInstruWithLevel) {
InstrusNamesVC *instrusRootVC = [[InstrusNamesVC alloc]
initWithTabInstruTypeNames: myPartitionInfos.partTabInstruNames
WithTabAllInstrusModel: myPartitionInfos.partTabInstrus
WithTabAllAnnPartByInstru: tabAnnotationsPartitionByInstru];
navController = [[UINavigationController alloc] initWithRootViewController:instrusRootVC];
} else {
if ([myPartitionInfos.partTabInstrus count] > 1)
{
InstrusViewController *instrusRootVC = [[InstrusViewController alloc] initWithTabInstrusModel:myPartitionInfos.partTabInstrus WithTabAnnPartByInstru:tabAnnotationsPartitionByInstru];
navController = [[UINavigationController alloc] initWithRootViewController:instrusRootVC];
}
// We only have one instru, we skip the instru selection step
else
{
InstruPartitionVersionsVC *instrusRootVC = [[InstruPartitionVersionsVC alloc] initWithIndexInstru: 0
WithTabAnnPartByInstru: tabAnnotationsPartitionByInstru];
navController = [[UINavigationController alloc] initWithRootViewController:instrusRootVC];
}
}
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.preferredContentSize = CGSizeMake(400.0, 600.0);
navController.popoverPresentationController.sourceView = self.view;
navController.popoverPresentationController.sourceRect = sender.frame;
navController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
navController.popoverPresentationController.delegate = self;
navController.navigationBar.translucent = NO;
navController.navigationBar.tintColor = SCROLL_COLOR_MMR;
if(APPDESIGN== kDesignPinkPanther){
navController.navigationBar.barTintColor = [UIColor colorWithRed:240/255.0 green:138/255.0 blue:177/255.0 alpha:1.0];
navController.popoverPresentationController.backgroundColor = [UIColor colorWithRed:240/255.0 green:138/255.0 blue:177/255.0 alpha:1.0];
} else if (APPDESIGN== kDesignCarmen){
navController.navigationBar.barTintColor = [UIColor colorWithRed:193/255.0 green:38/255.0 blue:67/255.0 alpha:1.0];
navController.popoverPresentationController.backgroundColor = [UIColor colorWithRed:193/255.0 green:38/255.0 blue:67/255.0 alpha:1.0];
} else {
navController.navigationBar.barTintColor = BROWN_COLOR_MMR;
navController.popoverPresentationController.backgroundColor = BROWN_COLOR_MMR;
}
[self presentViewController:navController animated:YES completion:nil];
in instruViewController for example the code is as follow:
- (id)initWithTabInstrusModel: (NSArray *)pTabInstru
WithTabAnnPartByInstru: (NSArray *)pTabAnn
{
self = [super initWithNibName:@"InstrusViewController" bundle:[NSBundle mainBundle]];
if (self != nil)
{
tabInstrusModel = pTabInstru;
tabAnnPartByInstru = pTabAnn;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// init properties
self.tabInstrusItems = [NSMutableArray array];
// Init tabInstruItems
for (int i = 0; i < [tabInstrusModel count]; i++)
{
InstrumentPartitionModel *instruTMP = [tabInstrusModel objectAtIndex:i];
[tabInstrusItems addObject:locStr(instruTMP.instruName)];
}
// let selection done before
self.clearsSelectionOnViewWillAppear = NO;
// set background custom
self.tableView.backgroundColor = [UIColor clearColor];
UIImage *backgroundImage = [UIImage imageNamed:@"bg_popup.png"];
UIImageView *backgroundImageView = [[UIImageView alloc]initWithImage:backgroundImage];
backgroundImageView.frame = self.tableView.frame;
self.tableView.backgroundView = backgroundImageView;
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.rowHeight = 50.0;
// Set navigation bar title
UILabel *label = [[UILabel alloc] init];
[label formatAsTitlePopover:@""];
[self.navigationItem setTitleView:label];
then I experimented with 1) not specifying anything for self.navigationItem.backBarButtonItem 2) using this:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self.navigationController action:@selector(popViewControllerAnimated:)];
3) using this:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
But this does not change anything (except that when I do not specify anything, the back button display "back"): the button remains inactive. I even tried to put
self.navigationItem.backBarButtonItem.enabled = YES;
without any success.
Then the didSelectRowAtIndexPath is as follows:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[(CustomUITableView *)tableView updateCellSelect : indexPath];
InstruPartitionVersionsVC *versionsVC = [[InstruPartitionVersionsVC alloc]
initWithIndexInstru: indexPath.row
WithTabAnnPartByInstru: tabAnnPartByInstru];
// In case of MultiInstruWithLevel, tabAnnPartByInstru only contains partitions for the selected instr type:
if (APPTYPE == kTypeMultiInstruWithLevel) {
NSArray * tabAnnPartTMP = [tabAnnPartByInstru objectAtIndex:indexPath.row];
AnnotationsPartitionModel *annPartTMP = [tabAnnPartTMP objectAtIndex:0];
versionsVC.indexGlobal = annPartTMP.annPartInstruDisplay;
} else {
versionsVC.indexGlobal = indexPath.row;
}
// Display new Controller
[[self navigationController] pushViewController:versionsVC animated:YES];
}
And so on for the next TableViewControllers...
I checked that all table views controller put on the stack have the same size.
Now, I really do not know what I could check....