문제

I know how to change between tabs when I am currently on one of the views presented by the tab controllers, using this:

self.tabBarController.selectedIndex=1;

But right now I need to change between tabs while on a modal child view, I need the modal view to be dismissed and the other tab to be shown,

도움이 되었습니까?

해결책

The best/proper pattern for this is to have the modal child hand off the task to its delegate as it exits. Define your own simple "myChildViewDelegate" protocol (could be a single method, even), and give the modal child a "delegate" property like so:

id<myChildViewDelegate> delegate;

When the user presses a button or whatever on the modal view, it calls a method on its delegate and the delegate dismisses the modal view and changes tabs.

다른 팁

Assuming you have some sort of button on the presented view controller just set that buttons target to a function in the presenting view.

-(void) someFunction {
    ... Code that creates the modal view controller and buttons

    [modalViewController.changeTabButton addTarget: self action:@selector(changeTab:) forControlEvents:UIControlEventTouchUpInside];

    [self presentViewController:modalViewController animated:YES completion:nil];
}

-(void) changeTab:(id)sender {
    self.tabBarController.selectedIndex=1;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top