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

前端 未结 2 473
無奈伤痛
無奈伤痛 2021-01-16 01:17

I am using Xcode 4.3.1. I have created the UI using Storyboard which has many View Controllers.

Issue

In my app i am usin

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-16 01:55

    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.

提交回复
热议问题