2012-04-19 1 views
0

私はナビゲーションベースのアプリケーションを構築しています(ナビゲーションコントローラに埋め込まれたビューはほとんどありません)。 前のビュー(ビューA)のビューBの内部からtitleプロパティを取得でき、NSLogなどのタイトルプロパティを取得できるかどうかは疑問です!Cocoa:前のビューのタイトルを取得する

おかげ

ルカ

答えて

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

クラス .mファイル

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