gpt4 book ai didi

objective-c - 如何从其他 View Controller 访问属性

转载 作者:行者123 更新时间:2023-12-04 04:51:31 24 4
gpt4 key购买 nike

我正在使用 Xcode 4.6.1 为 iOS 6 进行开发。

我有两个 View Controller :viewController1viewController2 .我正在尝试访问 viewController1 中定义的属性在 viewController2如下(但它不起作用):

这是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 *'
}

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

谢谢! :)

最佳答案

你有你的 videoPlayer您在 viewController1.m 中定义的属性,但您导入 viewController1.h .

搬家 videoPlayerviewController1.h .请勿导入 viewController1.m .

关于objective-c - 如何从其他 View Controller 访问属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17368455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com