質問

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