2

Hello guy's and girl's,

I got a question, i'm new to objective c and iphone apps. But i'm trying to make a few simple applications but i have trouble with creating a segue that also sets the label in the next view controller.

The situation is as following. i have a Tableviewcontroller with an loaded nsarray of data. Next i have created a segue (ctrl + drag). Al works so far. Now the viewcontroller has an label, i have namend the segue and a'm trying the following code.

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"ShowTitleInOtherViewController"]) {
        PracticeViewController *pvc = [segue destinationViewController];
        pvc.labelForDisplayData.text = @"Segue complete";
        pvc.labelForDisplayData.textColor = [UIColor blueColor];
        pvc.labelForDisplayData.font = [UIFont boldSystemFontOfSize:50];
    }
}

i have imported the header and the viewcontroller header looks like the following:

@interface PracticeViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *labelForDisplayData;

@end

Please tell me what i am doing wrong. (there are no error's)

Msmit1993
  • 1,710
  • 4
  • 21
  • 35

2 Answers2

0

Make the Label property to strong instead of weak

@interface PracticeViewController : UIViewController

@property (strong, nonatomic) IBOutlet UILabel *labelForDisplayData;

@end
Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
0

Recommendation

From your description (as long as you've connected the outlet in your storyboard) then this workflow should be okay. You are not showing how the segue is initialized (i.e., performSegueWithIdentifier). Please see this stack overflow question for more details (link). I've posted a few tips on manual segueing. If you've resolved this issue please update your original question. Here is another sample of calling a manual segue (link). Please advise if this issue is still open or share the problem/solution.

New Apple Tutorial on Storyboards

Hope this helps.

Community
  • 1
  • 1
Tommie C.
  • 12,895
  • 5
  • 82
  • 100