2011-06-25 111 views
0

我正在製作應用程序,就像設備改變其定向模式時它改變它的視圖一樣。
第一次當視圖是肖像時,它顯示完美的SearchViewController,然後當我旋轉到風景時推動到新的視圖MapView在風景......現在當我再次改變視圖到肖像地圖旋轉到肖像......但它應該做的搜索視圖控制器......還有一件事情,當我挖掘細節泄露按鈕它應該回去搜索視圖控制器...我認爲導航控制器不能在地圖視圖中工作..U導航控制器沒有工作

這是searchViewController

我的代碼部分
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 


    //return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    if(interfaceOrientation == UIInterfaceOrientationPortrait|| inte rfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
    } 
    else { 
     MapView *mapView = [[MapView alloc] initWithNibName:@"MapView" bundle:nil]; 
     mapView.title = @"Map"; 
     [self.navigationController pushViewController:mapView animated:YES]; 
     return YES; 

    } 
    return YES; 

} 

,這是我的MapView代碼

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    // return (interfaceOrientation == UIInterfaceOrientationLandscapeRight|| UIInterfaceOrientationLandscapeLeft); 
    if(interfaceOrientation == UIInterfaceOrientationPortrait|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     NSLog(@"hi Potrait"); 
     [self.navigationController popViewControllerAnimated:NO]; 
     return YES; 
    } 
    else { 
    } 
    return YES; 
} 
+0

請格式化你的代碼下一次。它使它更具可讀性。 – PengOne

回答

1

shouldAutorotateToInterfaceOrientation:是一個不正確的地方來實現任何類型的導航。您應該使用didRotateFromInterfaceOrientation:來代替。檢查當前的interfaceOrientation並在必要時按下或彈出。

searchViewController

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { 
     MapView *mapView = [[MapView alloc] initWithNibName:@"MapView" bundle:nil]; 
     mapView.title = @"Map"; 
     [self.navigationController pushViewController:mapView animated:YES]; 
    } 
} 

MapView

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { 
     [self.navigationController popViewControllerAnimated:NO]; 
    } 
} 

,並改變你的shouldAutorotateToInterfaceOrientation:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 
+0

::))))非常感謝..這真的很棒.... – Hiren