7

当我点击屏幕时,我使导航栏(顶部栏)出现/消失,并且还位于背景图像的顶部。它有效,但有一个问题:我突然有两个导航栏!首先,一个带有名为“Back”的后退按钮,当我按下“Back”时,它会弹出一个带有名为“Vinene”的后退按钮的新导航栏,这是它返回的 TableView 的标题。那是我想保留的。我认为问题出在 DetailViewController.m 或 MasterViewController.m 中的 didselectrowatindexpath 中。希望有人能看到问题!

DetailViewController.m:

@interface WinesDetailViewController ()

@end

@implementation WinesDetailViewController

@synthesize wineDictionary;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

self.navigationController.navigationBar.translucent = YES;
                         self.wantsFullScreenLayout = YES;

UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideShowNavigation)] autorelease];
                                                                                                         tap.numberOfTapsRequired = 1;
                                                                                                 [self.view addGestureRecognizer:tap];
}

- (void) hideShowNavigation
{
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden];
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)hidesBottomBarWhenPushed{
return TRUE;
}


@end

MasterViewController.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];    

    NSDictionary *dictionary = [wine libraryItemAtIndex:indexPath.row];

    if (winesDetailViewController == nil) {
        // Init the wine detail view
        winesDetailViewController = [[WinesDetailViewController alloc] init];
    }
    // Here you pass the dictionary
    winesDetailViewController.wineDictionary = dictionary;

    [self.navigationController pushViewController:winesDetailViewController animated:YES];
    }
}
4

1 回答 1

4

通常,像您描述的重复导航栏是由两次推送同一个视图控制器引起的。您能否检查以确保您仅将单个视图控制器推送到导航堆栈(通过断点或日志记录?)。winesDetailViewController 是否可能已经在导航堆栈上?您还可以尝试记录self.navigationController.viewControllers提示的值。

我也建议搬家

self.navigationController.navigationBar.translucent = YES;

查看WillAppear 和

self.wantsFullScreenLayout = YES;

到您的初始化程序(尽管我认为这不会解决您的问题)。

于 2012-06-26T00:55:00.813 回答