我正在维护一个基于xib文件的旧代码。 一切正常,但最近,弹出窗口中导航栏的后退按钮不再响应。 我从使用UIPopoverController变为使用UIModalPresentationPopover样式呈现导航控制器但没有任何改变。 这就是我正在做的事情:
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];
其中instrusRootVC是使用initWithNibName初始化的表视图控制器
在instrusRootVC中,我然后调用
[[self navigationController] pushViewController:secondVC animated:YES];
其中secondVC是使用initWithNibName初始化的新表视图控制器
除了导航栏的后退按钮没有响应外,一切正常。
(如果我打电话
[[self navigationController] popViewControllerAnimated:YES];
在第二个VC的某个地方,它运行正常。)
我做错了什么?
完整的代码太长了,无法进行评论,所以这里是:
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];
例如,在instruViewController中,代码如下:
- (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];
然后我进行了实验
1)没有为self.navigationItem.backBarButtonItem指定任何内容
2)使用这个:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self.navigationController action:@selector(popViewControllerAnimated:)];
3)使用这个:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
但这并没有改变任何东西(除非我没有指定任何东西,后退按钮显示“后退”):按钮保持不活动状态。 我甚至试图把
self.navigationItem.backBarButtonItem.enabled = YES;
没有任何成功。
然后didSelectRowAtIndexPath如下:
- (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];
}
等下一个TableViewControllers ......
我检查过放在堆栈上的所有表视图控制器都有相同的大小。
现在,我真的不知道我能检查什么......
答案 0 :(得分:0)
我仍然不明白为什么默认后退按钮突然停止响应,但我发现使用左侧栏按钮的转身工作正常,我想分享它。
我所做的是在每个viewController的viewDidLoad方法中添加以下行,这些方法旨在由作为popOver的导航控制器推送:
if (self != [self.navigationController.viewControllers objectAtIndex:0])
{
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"ico_back_popover.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(leftBtnPressed:)];
}
其中leftBtnPressed如下:
-(IBAction)leftBtnPressed:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}