Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios导航栏';s后退按钮在popover中没有响应_Ios_Objective C - Fatal编程技术网

ios导航栏';s后退按钮在popover中没有响应

ios导航栏';s后退按钮在popover中没有响应,ios,objective-c,Ios,Objective C,我正在维护一个基于xib文件的旧代码。 一切正常,但最近,流行音乐中导航栏的后退按钮不再响应。 我从使用UIPopoverController更改为使用UIModalPresentationPopover样式显示导航控制器,但没有任何更改。 以下是我正在做的: navController = [[UINavigationController alloc] initWithRootViewController:instrusRootVC]; navController.modalPresentat

我正在维护一个基于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初始化的新表视图控制器

除了导航栏上的“后退”按钮没有响应外,一切正常

(如果我打电话

在secondVC的某个地方,它工作得很好。)

我做错了什么

完整代码太长,无法放入注释中,因此如下所示:

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];
3) 使用此选项:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self.navigationController  action:@selector(popViewControllerAnimated:)];
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];
 }
-(IBAction)leftBtnPressed:(id)sender
{
  [self.navigationController popViewControllerAnimated:YES];
}
等下一个TableViewController

我检查了所有放置在堆栈上的表视图控制器是否具有相同的大小


现在,我真的不知道我可以检查什么…

我仍然不明白为什么默认的后退按钮突然停止响应,但我发现使用左栏按钮可以正常工作,我想与大家分享一下

我所做的是在每个viewController的viewDidLoad方法中添加以下行,这些viewController将由显示为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如下所示:

 - (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];
 }
-(IBAction)leftBtnPressed:(id)sender
{
  [self.navigationController popViewControllerAnimated:YES];
}

给我看你带来解决方案的完整代码。条形按钮是否可见?请浏览此链接-是的,后退按钮可见但不活动。以下是完整的代码:我用完整的代码编辑了我的第一篇文章,并解释了我的尝试。