2011-02-02 58 views
1

我想,當用戶點擊一個註解推看法,我在的地方下面的代碼:上的註釋時,點擊推視圖

- (void) mapView: (MKMapView *) mapView annotationView:(MKAnnotationView *) view calloutAccessoryControlTapped:(UIControl *) control 
{ 
    childController = [[NeighborProfileViewController alloc] initWithNibName:@"NeighborProfileViewController" bundle:nil]; 
    childController.title = view.annotation.title; 
    childController.uid = [((NeighborMapAnnotation *)(view.annotation)) uid]; 
    [self.navigationController pushViewController:childController animated:YES]; 
} 

我知道這個代碼片段內執行因爲我試圖打印出一些東西,而且確實打印出來了。然而,爲什麼它不改變我已經推動的觀點?

這是因爲這個視圖實際上是主視圖的子視圖,它實際上有導航控制器?如果是這種情況,那我該如何解決這個問題。下面是加載子視圖代碼:

-(IBAction) toggleAction:(id) sender { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; 

    if(self.navigationItem.rightBarButtonItem.title == @"List"){ 
     self.navigationItem.rightBarButtonItem.title = @"Map"; 
     [mapViewController.view removeFromSuperview]; 
    }else { 
     [self.view addSubview:mapViewController.view]; 
     [self.view sendSubviewToBack:self.view]; 
     self.navigationItem.rightBarButtonItem.title = @"List"; 
    } 

    [UIView commitAnimations]; 

} 

換句話說calloutAccessoryControlTapped是的MapViewController

回答

0

你的代碼中是不足以回答以下問題:

是您的導航控制器初始化? 即使你打電話self.navigationController,如果它是nil,那麼什麼都不會發生。

xib名拼寫是否正確?如果您將控制器壓入導航堆棧並顯示錯誤的xib名稱,則可能不會拋出錯誤,並且您的控制器不會被推入堆棧。

編輯:

你需要你顯示你的初始視圖之前創建一個UINavigationController的一個實例。以下是展示模式視圖的示例:

YourViewController* rootViewController; /* however you are creating the initial view */; 

UINavigationController navController = 
     [[UINavigationController alloc] initWithRootViewController:rootViewController]; 

[rootViewController release]; 

[self presentModalViewController:navController animated:YES]; 
[navController release]; 
+0

xib是正確的,代碼是一樣的確切的事情,我用來推一個控制器時,用戶在表視圖 – aherlambang 2011-02-02 04:24:44

0

您的mapviewcontroller沒有對導航控制器的引用。你的主視圖控制器。所以你需要做的就是將你的導航控制器的引用傳遞到maview控制器上,並將視圖推送到該控制器上。讓我知道如果您有任何問題

相關問題