2012-04-19 28 views
0

我正在構建一個基於導航的應用程序(嵌入在導航控制器中的幾個視圖)。 我想知道如果我可以從視圖B的前一個視圖(視圖A)和NSLog的例如!可可:獲取上一個視圖的標題

感謝

盧卡

回答

0

當然可以。

看看UINavigationController的viewControllers屬性。

返回用戶當前正在查看的視圖控制器的數組。因此,查看最後一個視圖控制器(或「n-2,其中n是數組中的項目數量」,according to the Apple documentation I linked for you),並且您可以從該視圖控制器的導航欄中獲取標題。

0
NSMutableArray *activeControllerArray = [self.navigationController.viewControllers mutableCopy]; 

ControllerA myController; 
For(int i = 0, i <[activeControllerArray count], i++) { 
    if([[activeViewController objectAtIndex:i] isKindOfClass:[ControllerA class]) { 
     myController = [activeViewController objectAtIndex:i]; 
     NSLog(@"%@",myController.title); 
    } 
} 
0

ViewControllerA * viewA =(ViewControllerA *)[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];

NSLog(@「%@」,viewA.title);

0

A類 .m文件

{ 
    NSString *titleA = @"Khalid"; 
    ClassB *bObj = [[ClassB alloc] init]; 
    bObj.title = titleA; 
    [self.navigationController pushViewController:bObj animated:YES]; 
} 
相關問題