简体   繁体   中英

Data is not being passed to detail view controller in storyboards

So I know that this question has been answered before, but I feel like my issue is just some small detail I've overlooked. I'm trying to pass data between my view controllers using storyboards, but once I push I'm not getting anything on the other end.

Here's what I have in my seque push method:

if ([segue.identifier isEqualToString:@"DetailPush"]) {
    NSMutableDictionary *selectedObject = [self.userArray objectAtIndex:self.selectedIndexPath];
    PhotoStreamDetailViewController *destController = [segue destinationViewController];
    destController.label.text = selectedObject[kImage][kURL];
}
  • I have set a breakpoint to ensure that my object isn't 'nil' (there is data prior to passing).
  • I created an IBOutlet from the storyboard to the detail view controller

Perhaps there other things that I need to check?

Iboutlets are not set when prepareForSegue is called so in your code you're trying to set something that is equal to nil. Create a public property to store your string then set your label in viewDidLoad.

The IBOutlets won't be set until viewDidLoad . You'll want to pass in the data via a publicly exposed NSString on your view controller and then set it on viewDidLoad .

You can see a more in depth explanation here.

You can't set label text directly from ViewControllerA to ViewControllerB.

Create a NSString property in ViewControllerB interface:

@property (nonatomic) NSString *labelText;

Then pass this string forward from ViewControllerA to ViewControllerB:

PhotoStreamDetailViewController *destController = [segue destinationViewController];

destController.labelText = selectedObject[kImage][kURL];

And in ViewControllerB, ie viewDidLoad:

label.text = self.labelText;

Also you can try this:

    PhotoStreamDetailViewController *destController = [segue destinationViewController];
    [destController loadView];
    destController.label.text = selectedObject[kImage][kURL];

That way you avoid the NSString property to pass the text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM