-1

我在情节提要上创建了两个视图控制器,我想以编程方式从一个视图控制器转到另一个视图控制器。我在一个视图控制器中创建了一个按钮。我知道从一个视图控制器到另一个视图控制器很容易,只需将按钮从一个视图控制器拖到第二个视图控制器。但我想以编程方式执行此操作,因为我在按钮中有 if 和 else 条件,如果条件为真,那么我想将它移动到下一个视图控制器这是代码。

-(IBAction)loadView:(id)sender {
    if([username.text isEqualToString:@"adnan"] && [password.text isEqualToString:@"bhatti123"] )
    {
        // here I want to write that code which reach me to second view controller which I implement on storyboard 

    }   
    else 
    {

    }
}
4

3 回答 3

3

将线从第一个视图控制器拖到第二个并设置 segue 的标识符:

.m文件中:

if([username.text isEqualToString:@"adnan"] && [password.text isEqualToString:@"bhatti123"] )
{
    [self performSegueWithIdentifier:@"nextView" sender:sender];
}   
else 
{

}
于 2012-12-07T11:13:58.700 回答
2
-(IBAction)loadView:(id)sender
{
      if([username.text isEqualToString:@"adnan"] && [password.text isEqualToString:@"bhatti123"] )
      {
         // here i want to write that code which reach me to second view controller which i implement on storyboard 
            SecondViewController *objSecondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
            [self.navigationController pushViewController:objSecondViewController animated:YES];
            [objSecondViewController release];
     }   
     else 
     { 
        //write your else part code here
     }
}

更新 :

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 
SecondViewController *objSecondViewController = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.navigationController pushViewController:objSecondViewController animated:YES];
于 2012-12-07T10:23:49.453 回答
0
SecondViewController *secondviewController = [[SecondViewController alloc] init];
[self presentviewController:secondviewController animation:YES completion:nil];

希望这可以帮助...

于 2012-12-07T10:26:04.287 回答