2012-06-26 34 views
5

Tôi đã tạo thanh điều hướng (thanh trên cùng) xuất hiện/biến mất khi tôi nhấn vào màn hình và cũng nằm ở trên cùng của hình nền. Nó hoạt động, nhưng với một vấn đề: tôi đột nhiên có hai thanh điều hướng! Đầu tiên, một với một nút quay lại có tên "Back", và khi tôi bấm "Back" nó sẽ bật lên một thanh điều hướng mới với một nút quay lại có tên "Vinene", đó là tiêu đề của TableView nó dẫn trở lại. Đó là điều tôi muốn giữ. Tôi nghĩ rằng vấn đề là một nơi nào đó trong DetailViewController.m hoặc trong didselectrowatindexpath trong MasterViewController.m. Hy vọng ai đó có thể nhìn thấy vấn đề!Thanh điều hướng hai chiều không mong muốn

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]; 
    } 
} 
+0

bài đăng hình ảnh vui lòng – Legolas

Trả lời

3

Thông thường, một thanh điều hướng lặp đi lặp lại như bạn mô tả là do một cái gì đó giống như đẩy bộ điều khiển xem hai lần. Bạn có thể kiểm tra để đảm bảo rằng bạn chỉ đang đẩy một bộ điều khiển chế độ xem duy nhất vào ngăn xếp điều hướng của mình (thông qua các điểm ngắt hoặc ghi nhật ký?). Có thể là các loại rượu vangDetailViewController đã có trên ngăn xếp điều hướng không? Bạn cũng có thể thử đăng nhập giá trị self.navigationController.viewControllers để biết gợi ý.

Tôi cũng xin đề nghị di chuyển

self.navigationController.navigationBar.translucent = YES; 

để viewWillAppear và

self.wantsFullScreenLayout = YES; 

để khởi tạo của bạn (mặc dù tôi không nghĩ rằng đây sẽ giải quyết vấn đề của bạn).

+0

Tôi đoán đó là vấn đề, nó có vẻ logic. Tôi cố gắng chuyển dữ liệu som từ một tableview đến một cái nhìn chi tiết nhưng nó phức tạp bởi vì tôi mới đến điều này. Tôi đã tạo một kết nối bảng phân cảnh từ ô mẫu thử đến chế độ xem chi tiết trong bảng phân cảnh và trong mã didselectrowatindexpath mà tôi đã đăng trong câu hỏi của mình. Nó hoạt động tốt cho đến nay ngoại trừ thanh đôi thứ. – ingenspor

+0

Nếu bạn đang sử dụng bảng phân cảnh theo cách đó, bạn có thể muốn sử dụng một cái gì đó giống như câu hỏi này gợi ý; không đẩy bộ điều khiển xem chi tiết của riêng bạn. http://stackoverflow.com/questions/8130600/use-didselectrowatindexpath-or-prepareforsegue-method-for-uitableview –

Các vấn đề liên quan