, 당신은을 통해 그 자식 UIViewControllers에 대한 참조 얻을 수 있습니다 : 당신이 그들을 설정 한대로,
[myTabBarController objectAtIndex:index];
NSLog(@"Selected view controller class type: %@, selected index: %d", [myTabBarController selectedViewController], [myTabBarController selectedIndex]);
0 기반 인덱싱 기법이 탭의 순서를 다음을 여부를 프로그래밍하거나 IB를 통해 (가장 왼쪽 탭 = 인덱스 0).
UIViewController 참조가 검색하는 것으로 보이기 때문에 (이름을 'InitialViewController'로 지정했기 때문에) rootViewController 인 것처럼 보이기 때문에 appDelegate에서도이 것을 시도 할 수 있습니다. 이 5 초 정도 걸립니다 :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"self.window.rootViewController = %@", NSStringFromClass([self.window.rootViewController class]));
UIViewController *myRootViewController = self.window.rootViewController;
}
가 그
당신이 UITabBarController가 또는 UINavigationController가를 사용하든, 나는 그 중 하나가 당신의 rootViewController입니다 확신합니다 :) 트릭을 않는 경우 알려주세요.코멘트에있는 NEW 세부 정보를 기반
InitialViewController* myInitialViewController;
for (UIViewController *vc in [myRootViewController childViewControllers]) {
if([vc isKindOfClass:[InitialViewController class]]){
//Store this reference in a local/global variable or a property,
//or simply perform some logic on the vc pointer if you don't need to store it.
myInitialViewController = (InitialViewController *)vc; //Example & reminder to cast your reference
}
}
편집 : 당신이 그것을에 대한 참조를 잡고 나면, 나머지는 꽤 쉽게
좋아, 당신의 topViewController의있는 viewDidLoad 또는 viewWillAppear에서이 코드를 실행 :
//You have to import this class in order to reference it
#import "MESHomeViewController.h"
//Global variable for storing the reference (you can make this a property if you'd like)
MESHomeViewController *myHomeVC;
int i = 0;
for (UIViewController *vc in [self.slidingViewController childViewControllers]) {
NSLog(@"Current vc at index %d = %@", i, [vc class]);
if ([vc isKindOfClass:[MESHomeViewController class]]) {
NSLog(@"Found MESHomeViewController instance - [[self.slidingViewController childViewControllers] objectAtIndex:%d]", i);
myHomeVC = vc;
break;
}
i++;
}
해당 참조를 사용할 수 있는지 확인하십시오. 그럴 경우, 여러분의 콘솔은 HomeViewController의 클래스 이름을 출력 할 것입니다.
나는 달성하려는 것에 대한 자세한 정보를 제공하는 편집으로 내 질문을 업데이트했습니다. 저에게 알려주세요. – StuartM
좋아요, 그 repo를 복제하고 예제 프로젝트를로드했습니다. 예제 프로젝트의 스토리 보드를 보면 어떤 ViewController (은유 적으로)이고 어떤 것을 참조하려고합니까? 이렇게하면 질문에 쉽게 답할 수 있습니다. – BigDan
감사합니다. 설명하기가 어렵습니다. 내가 화면에 내 로그인 VC를 가지고있다. 이것은 Stack Order에서 InitalViewController (bottom)와 같을 것입니다. topViewController 속성은 'WelcomeVC'(탐색 컨트롤러)이고, Login View Controller는 다음과 같습니다. 로드 된 초기보기 컨트롤러의보기 속성에 어떻게 액세스합니까? (화면의 로그인보기 컨트롤러의 imp 파일 내에서) – StuartM