将数据从一个viewcontroller传递到另一个

时间:2012-10-12 21:22:51

标签: objective-c ios uiviewcontroller viewcontroller

我将两个视图控制器子类化。

第一个应该传递数据,NSUrl对象传递给第二个。

.m的第一个:

NSURL *temp = [NSURL URLWithString:@"http://example.com"];

UIViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"];

presentationsFullScreen_ViewController.urlToUse = temp;

.h的第二个:

#import <UIKit/UIKit.h>

@interface PresentationsFullScreen_ViewController : UIViewController {


    NSURL *urlToUse;


}



@property (nonatomic,retain) NSURL *urlToUse;

它显然不起作用而且没有编译,基本上告诉我,我没有对它进行子类化,并且在UIViewController上找不到属性urlToUse。

我如何正确子类化?

谢谢!

2 个答案:

答案 0 :(得分:1)

这是正确的代码

 PresentationsFullScreen_ViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"];
presentationsFullScreen_ViewController.urlToUse = temp;

答案 1 :(得分:0)

解决方案:

不要忘记导入.h:

#import "PresentationsFullScreen_ViewController" 

并且不要使用UIViewController实例化对象,而是使用子类的名称实例化:

PresentationsFullScreen_ViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"];