【问题标题】:Passing data from one viewcontroller to another将数据从一个视图控制器传递到另一个
【发布时间】:2012-10-12 21:22:50
【问题描述】:

我继承了两个视图控制器。

第一个应该传递数据,一个 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。

如何正确子类化?

谢谢!

【问题讨论】:

  • 您是否将故事板中目标视图控制器的类设置为您的自定义子类?

标签: objective-c ios uiviewcontroller viewcontroller


【解决方案1】:

这是正确的代码

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

【讨论】:

  • 谢谢!!!是的,这很有帮助。谢谢你!现在这么明显。是的,我忘了导入我的 .h
  • 我接受这个答案感谢大家的帮助,但不需要更多答案!
【解决方案2】:

解决方法:

别忘了导入 .h:

#import "PresentationsFullScreen_ViewController" 

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    相关资源
    最近更新 更多