Passing Data from View Controller to Label in TableView

I am trying to pass data from one view controller to another view controller. Here is my code so far that I have tried, but I keep getting an error when using this code. The error says, "Outlets cannot be connected to repeating content.


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    SchoolLocationViewController *schoolLocation = [segue destinationViewController];
   
    if ([sender isEqual:btnAbington]) {
        schoolLocation.campusLocation = schoolLocation.campusLabel.text = @"Abington";
    }
}

➕try KVO

Not sure why you're trying to assign two things on the same line there. You should use separate assignment statements for clarity. In any case, you can't assign directly to your destination view controller's UI widgets from prepareForSegue. (It's bad style - a violation of MVC - but more importantly, the view has not yet been loaded at that point, so any outlets will be nil.)


prepareForSegue should pass data / info to the child - "here is the information you should display". It is up to the child to decide how and when to display it. Could be a UILabel, a UITextView, a UIButton, render fancy graphics into a UIImage, whatever - the parent should not know or care. The child should usually do this (populate its UI widgets based on the data it is supposed to display) in viewWillAppear.


I have no idea what that "repeating content" error message means, but I suspect you have done something funky / non standard in the way you've set up your outlets. Might be worthwhile to watch some videos where they do it (e.g. the Stanford CS193P course) and see what's different in your setup.

Passing Data from View Controller to Label in TableView
 
 
Q