첫 번째 탭에 HomePage의 ViewController가 포함 된 UITabBarController가있는 응용 프로그램이 있습니다. 필자가해야 할 일은 탭 간을 전환하는 것입니다 (이것은 매우 간단합니다 : [[self tabBarController] setSelectedIndex : index]), 그리고 "HomePage"에서 selectedTab의 아웃렛을 탐색하는 것입니다. 프로그래밍 방식으로 UITabBarController 사이를 전환하는 방법
그냥 자신을 설명하기 : TabElement1 ---> TabElementX ----> UISegmentedController : segmentY문제는 그것이 내가 할 최소한 처음으로 (아직 초기화되지 않기 때문에 UISegmentedController이 전무하다는 것이다 조작). 이 문제를 어떻게 해결해야합니까? 탭 요소는 닙으로로드됩니다. 내가 탭 인덱스 2, TGWebViewController에 들어가 관리 나는 playVideoPreview 해고 처음
@implementation HomeViewController // Tab Indexed 0
// ...
- (void)playVideoPreview {
NSArray *array;
array = [[self tabBarController] viewControllers];
// This is a test where I programmatically select the tab AND the switch.
[[[array objectAtIndex:2] switches] setSelectedSegmentIndex:1];
[[self tabBarController] setViewControllers:array];
}
@end
@implementation TGWebViewController // Tab Indexed 2
// ...
@synthesize switches; // In .h file: @property (nonatomic, retain) IBOutlet UISegmentedControl switches; Properly linked within the XIB.
- (IBAction)switchHasChangedValue {
// Foo operations.
}
자,하지만 스위치는 아직 존재하지 않는, 그래서 나는 나 자신을 찾을 : 여기
EDIT--
는 일부 코드입니다 첫 번째 세그먼트가 선택된 상태에서 "switches"라는 이름의 segmentedControl. HomeViewController로 돌아 가면 playVideoPreview가 다시 실행되고 올바른 동작을 얻습니다.
:
편집 여기에 코드 (이 도움이되기를 바랍니다)입니까? viewDidLoad, viewWillAppear 또는 App Delegate에서? – Ladislav
나는 당신이 이해할 수 있도록 몇 가지 코드를 붙여 넣을 것이다. – IssamTP