iPhone UITabBar - 如何切换标签视图?

时间:2011-06-20 18:07:54

标签: iphone uitabbarcontroller uitabbar switch-statement

您能告诉我切换标签视图的工作原理吗?因为在我的“sendPressed”和“cancelPressed”方法中,我正在尝试从第二个选项卡视图切换到第一个选项卡视图。但是截至目前我在“[[array objectAtIndex:2] setSelectedSegmentIndex:1]”行中收到错误。

#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

3 个答案:

答案 0 :(得分:2)

用这个代替那一行:

self.tabBarController.selectedIndex = 1;

选项卡索引从0开始。因此索引0将是第一个选项卡,索引1将是第二个选项卡等。

答案 1 :(得分:2)

尝试

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

答案 2 :(得分:1)

为什么不使用

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


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