首页 文章

从警报更改iOS选项卡视图

提问于
浏览
-1

我有一个带有2个标签视图的标签式应用程序 . 当用户在警报视图上按“确定”时,我想将视图从第二个选项卡更改为第一个选项卡 .

当我在按下的-IBAction按钮上使用它时,以下代码片段有效,但是当我在警报代码中使用它时它没有做任何事情:

self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];

为什么在我的SeondViewController.m中使用如下时不起作用

- (void)viewDidLoad {
[super viewDidLoad];?

UIAlertView *alert =[[UIAlertView alloc]
initWithTitle:@"Camera and Target coincident"
message:msg
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];

我刚刚学习这个,所以你能提供的任何东西都会有所帮助 .

当我使用以下代码时:if([theProjection Trans_Initialise] == 1){NSString * msg = nil; UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@“Camera and Target coincident”消息:msg delegate:self cancelButtonTitle:@“OK”otherButtonTitles:nil]; [alertView show];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
       if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"OK"]) {
           self.tabBarController.selectedIndex = 0;
       }
   }

我收到错误消息 - (void)alertView“无效的参数类型void到一元表达式”我是在做什么语法,还是(很可能)我不明白的东西?

1 回答

  • 0

    首先,您需要从警报视图中回拨代理,通知您有关单击的按钮 .

    您的警报视图应该像这样创建:

    UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Camera and Target coincident" message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    

    然后在你的m文件中实现该函数:

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"OK"]) {
            self.tabBarController.selectedIndex = 0;
        }
    
    }
    

相关问题