如果你的标签栏控制器连接到“IBOutlet
”(或有其他的参考),切换标签就像更新selectedIndex
属性(我为你链接了Apple文档)一样简单。
编辑:
你的代码改成这样。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// if you have connected your tab bar controller to an IBOutlet named myTabBarController
if(myTabBarController)
{
// first tab bar controller is zero, second tab bar controller is 1, etc.
myTabBarController.selectedIndex = 1;
} else {
NSLog(@"tabBarController is nil and probably not set correctly");
}
}
- (void)pressedButton:(id)sender {
UIAlertView * alertView =
[[UIAlertView alloc] initWithTitle:@"Snap it" message:@"Take a picture" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
if(alertView)
{
[alertView show];
}
}
此处假设您已将标签栏控制器正确设置为IBOutlet。另请注意,我已将警报视图上的“委托”设置为“自我”(即如果使用“self
”作为委托,则“clickedButtonAtIndex
”方法必须与&类别相同)。
感谢您的反馈。我非常新的编码,我怎么知道它是否连接到“IBOutlet”? –
如果您的标签栏控制器存在于您的故事板(或xib文件)中,您可以将其设置为“IBOutlet”并以此方式访问它。如果您完全使用代码创建标签栏,则可以将其引用为实例变量。 –
我发现了IBOutlet: @property(nonatomic,retain)IBOutlet UITableView * stepsTableView; 现在如何链接它的消息框? 干杯, F –