ios导航栏的后退按钮在弹出窗口中没有响应
问题描述:
我维护基于xib文件的旧代码。 一切工作正常,但最近,弹出窗口中导航栏的后退按钮不再响应。 我从使用UIPopoverController更改为使用UIModalPresentationPopover样式呈现导航控制器,但没有任何更改。 下面是我在做什么:ios导航栏的后退按钮在弹出窗口中没有响应
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
一切工作正常,除了导航栏的后退按钮不respo ND。
(如果我在secondVC叫
[[self navigationController] popViewControllerAnimated:YES];
的地方,它工作正常。)
我在做什么错?
完整的代码太长的意见去的,所以在这里它是:
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 ...
我检查了把堆栈上的所有表视图控制器具有相同的大小。现在
,我真的不知道我可以检查....
答
我还是不明白,为什么默认后退按钮突然停止响应,但我发现了一个周转使用左边栏按钮的工作原理好,我想分享它。
我所做的是增加在每个的viewController的viewDidLoad方法以下行旨在由呈现为酥料饼的导航控制器被推:
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];
}
请向我显示您提供解决方案的完整代码。 – user3182143
栏按钮是否可见? – user3182143
请通过此链接 - http://stackoverflow.com/questions/25319179/uipopoverpresentationcontroller-on-ios-8-iphone – user3182143