iPhone UITabBar - 如何切换选项卡视图?

发布于 2024-11-16 05:40:24 字数 974 浏览 2 评论 0原文

您能告诉我切换选项卡视图是如何工作的吗?因为在我的“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

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] setSelectedSegmentIndex: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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼眸 2024-11-23 05:40:24

将该行替换为:

self.tabBarController.selectedIndex = 1;

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

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.

A君 2024-11-23 05:40:24

尝试

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

Try

self.tabBarController.selectedIndex = 0; //first tab
小…红帽 2024-11-23 05:40:24

你为什么不直接使用

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


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

Why dont you just use

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


// 1 for second tab
// 2 for third tab .....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文