2013-03-07 2 views
3

을 선택 않습니다는 왜 tabbarController 지수를 프로그래밍 방식 나던 통화 위임 방법

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController; 
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController; 

하지만 시도 즉, 프로그래밍 같은 일을 할 수

[self.tabbarController setSelectedIndex:selectedIndexNo]; 

또는

[self.tabBarController setSelectedViewController:[self.tabBarController.viewControllers objectAtIndex:0]]; 

는 대리자 메서드가 호출되지 않습니다. 그 이유는 무엇입니까?

답변

0

코드를 통해 직접 설정하는 경우 대리자 메서드가 호출되는 시간임을 알고 있습니다. 그래서 당신이하고 싶은 것은 프로그램 적으로 인덱스를 설정할 때 할 수 있습니다. 호출되고있는 tabbardelegate에 메소드 aMethod를 호출하려고한다고 가정 해보십시오. 인덱스를 설정하자마자 메소드를 호출 할 수 있습니다.

[self.tabbarController setSelectedIndex:selectedIndexNo]; 
[self aMethod]; 
+0

난 내가 그렇게 할 수 알지만, 왜 것으로 생각되는 방식으로 작동 나던? – yunas

+0

이것이 작동하는 방식입니다. –

+0

당신은 위임자 메소드를 직접 호출 할 수 있습니다.하지만 올바른 일은 아니지만 우연히 할 수 있습니다. [self.tabbarController setSelectedIndex : selectedIndexNo]; [YourViewControllerObject tabBarController : self.tabBarController didSelectViewController : [self.tabBarController.viewControllers objectAtIndex : selectedIndexNo] – Haider

4

재정 UITabBarController가 setSelectedIndex :

-(void)setSelectedIndex:(NSUInteger)selectedIndex 
{ 
    //must call super function. 
    [super setSelectedIndex:selectedIndex]; 

    [self myMethod]; 
} 

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    [self myMethod]; 
}