0

그래서, 나는 tabbarcontroller가 있고, tabBarItem을 건 드리면 dismissModalViewController에 알림을 전달합니다.NSNotification 문제 및 모달보기 컨트롤러 해제

잘 작동하고 모달 뷰 컨트롤러가 닫힙니다. 하지만 특정 방식으로 변경하고 싶습니다. 예상대로 작동하지 않습니다 ...

알림을 게시하기 전에 옵저버를 초기화했습니다. 이들은 tabBarItems 있습니다 -

NSArray *viewControllerss = [[NSArray alloc] initWithObjects: myProfileDataViewController, 
sampleViewController,reminderInfoViewController, nil]; 


[self.tabBarContr setViewControllers:viewControllerss animated:YES]; 
self.tabBarContr.selectedIndex = 2; 

나는 sampleViewControllerviewWillAppear에 알림을 보내고 나는 tabBarIcon이는 TabBarController를 일축 것을 선택할 때.

하지만 UITabBar의 왼쪽에 sampleViewController을 가장 넣고 싶습니다.

그리고는 그래서

NSArray *viewControllerss = [[NSArray alloc] initWithObjects: sampleViewController, 
myProfileDataViewController, reminderInfoViewController, nil]; 

본 닫지 않습니다 탭 표시 줄 컨트롤러처럼 추가합니다.

참고 :가있는 NSArray가 초기화되는 순서를 참조하십시오.

통지는 통지를 게시 직전

답변

0

당신이 NSLog를 넣을 수 모달 뷰 컨트롤러를 제공 각각의 뷰 컨트롤러에 viewWillAppear of sampleViewController` 및 관찰자에 게시?

앱이로드 될 때 출력이 표시되는지 확인합니다.

편집 : 당신의 sampleViewController에서

응답

에 따라 대답에 추가하면이를 시도 할 수 :

그것이 UITabBarControllerDelegate을 준수합니다. 당신의 sampleViewController의하는 .m에서 다음

@interface SampleViewController : UIViewController <UITabBarControllerDelegate> 

의 viewDidLoad에의 sampleViewController (이 경우 자기)

-(void) viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Assuming you have a reference to your tabBarController somewhere 

    [self setDelegate:self]; // try this line or the line below 
    // [[self tabBarController] setDelegate:self]; 

    // The rest of your drawing code here 
} 

할 대리자를 설정 : 귀하의 sampleViewController 클래스 인터페이스는 다음과 같이해야한다 이제 sampleViewController .m 파일의 어딘가에 델리게이트 메소드를 구현하십시오.

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    // I've included this to see if this method actually gets called or not. 
    NSLog(@"Dismissing modal view controller"); 

    // check to make sure sampleViewController tab was pressed by checking 
    // the class type of the viewController parameter being passed in 

    if ([viewController isKindOfClass:[SampleViewController class]] 
    { 
     // I assume you have a pointer reference to that modal view controller 
     // you want to dismiss 
     [self dismissModalViewController:theUnwantedViewController animated:YES]; 
    } 


} 

작동하는지 확인하십시오.

+0

전 항상 NSLog를 사용하고 있습니다. 알림이 전송되고 관찰자가 준비되었습니다. 모달보기'sampleViewController'가 배열 – Legolas

+0

에 처음 추가 될 때 해제되지 않습니다. NSLog의 출력을 얻었습니까? 탭 사이를 전환하면 viewWillAppear 메서드가 트리거되는지 궁금합니다. – Zhang

+0

예, viewWillAppear을 트리거하지 않았습니다. – Legolas