问题
I subclassed two view controllers.
The first one is supposed to pass data, a NSUrl object to the second one.
.m of the first one:
NSURL *temp = [NSURL URLWithString:@"http://example.com"];
UIViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"];
presentationsFullScreen_ViewController.urlToUse = temp;
.h of the second one:
#import <UIKit/UIKit.h>
@interface PresentationsFullScreen_ViewController : UIViewController {
NSURL *urlToUse;
}
@property (nonatomic,retain) NSURL *urlToUse;
It is obviously not working and not compiling,telling me essentially that I didn't subclass it and that the property urlToUse is not found on UIViewController.
How do I subclass correctly?
Thanks!
回答1:
It is correct code
PresentationsFullScreen_ViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"];
presentationsFullScreen_ViewController.urlToUse = temp;
回答2:
Solution:
don't forget to import the .h:
#import "PresentationsFullScreen_ViewController"
and dont instantiate the object with UIViewController but rather with the name of the subclass:
PresentationsFullScreen_ViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"];
来源:https://stackoverflow.com/questions/12867295/passing-data-from-one-viewcontroller-to-another