iPhone UITabBar - 如何切换选项卡视图?
您能告诉我切换选项卡视图是如何工作的吗?因为在我的“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将该行替换为:
选项卡索引从 0 开始。因此索引 0 将是第一个选项卡,索引 1 将是第二个选项卡,依此类推。
replace that line with this:
tab indexes start at 0. so index 0 would be the first tab, index 1 would be the second tab etc.
尝试
Try
你为什么不直接使用
Why dont you just use