[英]iPhone UITabBar - how do you switch tab views?
您能告诉我切换标签视图的工作方式吗? 因为在我的“ 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
将该行替换为:
self.tabBarController.selectedIndex = 1;
标签索引从0开始。因此索引0是第一个标签,索引1是第二个标签,依此类推。
尝试
self.tabBarController.selectedIndex = 0; //first tab
你为什么不使用
self.tabBarController.selectedIndex = 0; // for first tab
// 1 for second tab
// 2 for third tab .....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.