Passing data from one viewcontroller to another

坚强是说给别人听的谎言 提交于 2020-01-14 06:54:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!