squarefrog
squarefrog

Reputation: 4832

Update parent label from within a view controller?

I'm trying to update a label on a parent view, but I don't seem to be able to figure it out. My app is a Master/Detail type app. Within the Detail view, I have a UIScrollView, with 5 or so new view controllers inside, each displaying an image.

When an image is touched, I want the label on the Detail view to be updated. In my custom View Controller.h I have the following:

#import <UIKit/UIKit.h>
#import "UltimateRageAppDelegate.h"
#import "DetailViewController.h"

@interface MyViewController : UIViewController {

    DetailViewController *vc;

}

@property (nonatomic, retain) DetailViewController *vc;

@end

And in my View Controller.m file I have:

#import "MyViewController.h"

@implementation MyViewController

@synthesize vc, imageShow, imageName;

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

vc.clipboardLabel.text  = @"DID THIS WORK?";
NSLog(@"touches ended");

}

@end

I can't figure out why this doesn't work. I've declared and synthesised an IBOutlet clipboardLabel in my DetailViewController, and I can update the label from within DetailViewController no problems.

Upvotes: 0

Views: 335

Answers (1)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

It looks like you've not set your vc property properly. You should set it when you are creating your MyViewController instance.

MyViewController * viewController = [[MyViewController alloc] init];
viewController.vc = self;
[..]

This is assuming that you are in DetailViewController.

Upvotes: 1

Related Questions