私はナビゲーションベースのアプリケーションを構築しています(ナビゲーションコントローラに埋め込まれたビューはほとんどありません)。 前のビュー(ビューA)のビューBの内部からtitleプロパティを取得でき、NSLogなどのタイトルプロパティを取得できるかどうかは疑問です!Cocoa:前のビューのタイトルを取得する
おかげ
ルカ
私はナビゲーションベースのアプリケーションを構築しています(ナビゲーションコントローラに埋め込まれたビューはほとんどありません)。 前のビュー(ビューA)のビューBの内部からtitleプロパティを取得でき、NSLogなどのタイトルプロパティを取得できるかどうかは疑問です!Cocoa:前のビューのタイトルを取得する
おかげ
ルカ
はいすることができます。
UINavigationControllerのviewControllers
プロパティを見てください。
これは、ユーザーが現在見ているビューコントローラーの配列を返します。だから最後のビューコントローラ(または "n-2、ここでnは配列内の項目の番号"、according to the Apple documentation I linked for you)を見て、そのビューコントローラのナビゲーションバーからタイトルを取得できます。
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);
}
}
ViewControllerA * viewA =(ViewControllerA *)[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2]。
NSLog(@ "%@"、viewA.title);
クラス .mファイル
{
NSString *titleA = @"Khalid";
ClassB *bObj = [[ClassB alloc] init];
bObj.title = titleA;
[self.navigationController pushViewController:bObj animated:YES];
}