2013-06-28 130 views
1

我使用的Xcode 4.6.1开发的iOS 6如何从其他视图控制器

我有两个视图控制器访问性能。我想在viewController2访问viewController1定义的属性如下(但不工作):

这是viewController1.m

#import "viewController1.h" 

@interface viewController1() 

@property (nonatomic) MPMoviePlayerController *videoPlayer; 

@end 

@implementation viewController1 

... 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    ... 

    self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 

    ... 

    [self.videoPlayer play]; 

    ... 
} 

这是viewController2.m

#import "viewController2.h" 
#import "viewController1.h" 

@interface viewController2() 

@end 

@implementation viewController2 

... 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    viewController1 *thePlayer; 
    [thePlayer.videoPlayer pause]; 

    //This is where I get an error: 
    //Property 'videoPlayer' not found on object of type 'viewController1 *' 
} 

我已经尝试了很多搜索,但我无法弄清楚我做错了什么。任何帮助将不胜感激。

谢谢! :)

+0

你是否同时显示两个VC?使用'navigationController'?你在使用故事板吗? – Firo

+0

你的viewControllers如何连接?如果您使用segue从viewController1获取viewController 2,则可以使用prepareForSegue将引用传递给前端。否则,你可以使用委托。 – MichelleJS

+0

我正在使用故事板。 'viewController2'实际上是一个弹出窗口,显示在'viewController1'中 – wiseindy

回答

3

您已在viewController1.m中定义了videoPlayer属性,但导入了viewController1.h

videoPlayer移动到viewController1.h。请勿导入viewController1.m

+0

是的!这是问题!非常感谢。愚蠢的新手错误。现在很好用:) – wiseindy

相关问题