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

前端 未结 2 469
無奈伤痛
無奈伤痛 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.

    0 讨论(0)
  • 2021-01-16 01:56

    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];
    
    0 讨论(0)
提交回复
热议问题