【问题标题】:how to jump to specific viewController after click "yes"in a alertView在alertView中单击“是”后如何跳转到特定的viewController
【发布时间】:2016-02-04 12:20:25
【问题描述】:

单击 AlertView 中的按钮后,我想跳转到另一个 viewController。 谁能给我一个样品?

问题更新——————

我正在尝试这种方式:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

if ([cell.reuseIdentifier isEqualToString:@"Logoff"]){


    UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
                                                                   message:@“Logoff?"
                                                            preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* Confirm = [UIAlertAction actionWithTitle:@“Confirm" style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * action)

    {
        [alert dismissViewControllerAnimated:YES completion:nil];
        [self.performSegueWithIdentifier:@"ShowLoginView" sender:self];

        LoginViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
        [self.navigationController pushViewController:newView animated:YES];
    }];
    UIAlertAction* Cancel = [UIAlertAction actionWithTitle:@“Cancel" style:UIAlertActionStyleDefault
                                                   handler:^(UIAlertAction * action) {}];

    [alert addAction:Confirm];

    [alert addAction:Cancel];
    [self presentViewController:alert animated:YES completion:nil];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

}

但我收到了这个错误: 在“GeneralSettingsTableViewController *”类型的对象上找不到属性“performSegueWithIdentifier”

我错过了什么吗?

【问题讨论】:

  • 您能告诉我们您的尝试和遇到的问题吗?
  • 你试过了吗?
  • 您好,您有解决方案吗?否则我可以帮助您。

标签: ios uialertcontroller


【解决方案1】:

alertView 折旧使用UIAlertController 为例

 UIAlertController * alert=   [UIAlertController
                             alertControllerWithTitle:@"Info"
                             message:@"You are using UIAlertController"
                             preferredStyle:UIAlertControllerStyleAlert];

 UIAlertAction* ok = [UIAlertAction
                    actionWithTitle:@"OK"
                    style:UIAlertActionStyleDefault
                    handler:^(UIAlertAction * action)
                    {
                        [alert dismissViewControllerAnimated:YES completion:nil]; 
                    // here add your segue for navigation for another view Controller
            // If you already created the segue use this
            [self performSegueWithIdentifier:@"yoursegueName" sender:self];

          // if you are used Storyboard ID use this

             LoginViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.navigationController pushViewController:newView animated:YES];



                    }];
UIAlertAction* cancel = [UIAlertAction
                        actionWithTitle:@"Cancel"
                       style:UIAlertActionStyleDefault
                       handler:^(UIAlertAction * action)
                       {
                           [alert dismissViewControllerAnimated:YES completion:nil];

                       }];

[alert addAction:ok];
[alert addAction:cancel];

[self presentViewController:alert animated:YES completion:nil];

【讨论】:

  • 如果我想跳转到一个名为“LoginViewController”的 ViewController,请给我看一下“[alert dismissViewControllerAnimated:YES completion:nil];”下面的代码,我只知道“准备对于 segue"方式,它在这里不起作用。感谢 davance
  • 非常感谢,但我得到一个错误显示“在'MyViewController'的对象中找不到属性'performSegueWithIdentifier'。MyViewController是显示alertview的控制器。我必须声明它吗?跨度>
  • @H.JC -- 一个是连接通过,另一个是没有连接通过,你能把你的代码发送到我的邮件ID karthik.saral@gmail.com,我会做的工作
  • 但是如果我使用你的代码,我仍然会感到困惑,newViewController 将显示两次,我想知道为什么......
【解决方案2】:

试试这个把控制权传递给特定的viewController

- (void)viewDidLoad {
     [super viewDidLoad];
     [self showAlert];
}  

-(void)showAlert{
   UIAlertView *alertForCall = [[UIAlertView alloc]initWithTitle:@"" message:@"time to choose" delegate:self   cancelButtonTitle:@"NO" otherButtonTitles:@"Yes", nil];
     [alertForCall show];
}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1){
          thirdViewController *thirdView = [self.storyboard instantiateViewControllerWithIdentifier:@"third"];
          [self.navigationController pushViewController:thirdView animated:YES];
   }
}

【讨论】:

  • 不要使用 uialert 视图。已弃用
猜你喜欢
  • 2014-07-10
  • 1970-01-01
  • 2016-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-21
  • 1970-01-01
相关资源
最近更新 更多