开发者

iPhone UITabBar - how do you switch tab views?

开发者 https://www.devze.com 2023-03-14 09:01 出处:网络
Could you tell me how switching tab views work? Because in my \"sendPressed\" and \"cancelPressed\" methods I\'m trying to switch from the second tab view to the first tab view. However as of right no

Could you tell me how switching tab views work? Because in my "sendPressed" and "cancelPressed" methods I'm trying to switch from the second tab view to the first tab view. However as of right now I'm getting an error on the "[[array objectAtIndex:2] setSelected开发者_开发技巧SegmentIndex:1]" line.

#import "SecondViewController.h"

@implementation SecondViewController

- (IBAction) sendPressed:(UIButton *)sender
{
    array = [[self tabBarController] viewControllers];
    [[array objectAtIndex:2] setSelectedSegmentIndex:1];
    [[self tabBarController] setViewControllers:array];
}

- (IBAction) cancelPressed:(UIButton *)sender
{
    array = [[self tabBarController] viewControllers];
    [[array objectAtIndex:2] setSelectedSegmentIndex:1];
    [[self tabBarController] setViewControllers:array];

}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    imageView.image = image;
    [self dismissModalViewControllerAnimated:YES];
}

...
@end


replace that line with this:

self.tabBarController.selectedIndex = 1;

tab indexes start at 0. so index 0 would be the first tab, index 1 would be the second tab etc.


Try

self.tabBarController.selectedIndex = 0; //first tab


Why dont you just use

self.tabBarController.selectedIndex = 0;   // for first tab


// 1 for second tab
// 2 for third tab .....
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号