How to pass data from one View to other view in IOS using UIStoryboard segues?

送分小仙女□ 提交于 2019-12-01 13:06:22

You can pass the data explicitly and in storyboard that is with the prepareForSegue call.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([[segue identifier] isEqualToString:@"ContactsViewControllerSegue"]){
        ContactsViewController *cvc = (ContactsViewController *)[segue destinationViewController];
        cvc.contacts = self.contacts;
        cvc.delegate = self;
    }
}

For a full tutorial check out this website.

To programmatically trigger the segue you can check the Apple Docs, but here is their example on orientation change.

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
        !isShowingLandscapeView)
    {
        [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];
        isShowingLandscapeView = YES;
    }
// remainder of example omitted....
}

So you will trigger the segue when shaking stops, and then prepare the next viewController in the prepareForSegue method.

You need to create string object in SecondViewController and set Property(nonatomic,retain) and synthesize it and after below code add when you push controller.

SecondViewController *objSecondViewController=[[SecondViewController alloc] 
initWithNibName:@"SecondViewController" bundle:nil];             

objSecondViewController.strtitle=@"Your data";
[self.navigationController pushViewController:objSecondViewController animated:YES];
[objSecondViewController release];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!