[英]How to move from a view controller into other view controller in storyboard programmatically
I have create two view controller onto storyboard I wanted to go from one view controller to another view controller programmatically. 我已经在故事板上创建了两个视图控制器,我想以编程方式从一个视图控制器转到另一个视图控制器。 I have create a button in one view controller.
我已经在一个视图控制器中创建了一个按钮。 I know it very easy to go from one view controller to another just drag line from button from oneviewcontroller to second view controller.
我知道从一个视图控制器到另一个视图控制器很容易,只需将按钮的线从一个视图控制器拖动到第二个视图控制器即可。 but I want to do it programmatically because I have if and else conditions in button when if condition true then I want to move it to next view controller this is the code.
但我想以编程方式进行操作,因为当条件为true时,我在按钮中有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
{
}
}
Drag line from first view controller to second and set the identifier for segue: 将线从第一个视图控制器拖到第二个并设置segue的标识符:
In the .m
file: 在
.m
文件中:
if([username.text isEqualToString:@"adnan"] && [password.text isEqualToString:@"bhatti123"] )
{
[self performSegueWithIdentifier:@"nextView" sender:sender];
}
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
SecondViewController *objSecondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:objSecondViewController animated:YES];
[objSecondViewController release];
}
else
{
//write your else part code here
}
}
UPDATE : 更新:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
SecondViewController *objSecondViewController = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.navigationController pushViewController:objSecondViewController animated:YES];
SecondViewController *secondviewController = [[SecondViewController alloc] init];
[self presentviewController:secondviewController animation:YES completion:nil];
Hope this helps... 希望这可以帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.