XCode IBOutlet UIView 添加到 ViewControllers .h - UIViews 类型无法识别
我已将视图控制器的视图作为属性添加到支持 .h 文件 myViewController.h 的视图控制器中:
@property (weak, nonatomic) IBOutlet UIView* view;
在 myViewController.m 方法之一中编写 view.window 时,Xcode 会使用“property 'window'”将该行标记为错误在视图类型的对象上找不到”。它无法构建。注意我最初选择支持类 view.h 的视图作为类型。我已经清理了该项目。
具体来说,我在这里收到错误:
- (void)viewDidLoad
{
[super viewDidLoad];
displayLink = [view.window.screen displayLinkWithTarget:(self) selector:@selector(drawFrame)];
}
我该如何解决这个问题?我喜欢在视图控制器方法之一中访问视图控制器视图窗口。
I have added the view of my view controller as a property to the view controllers backing .h file myViewController.h:
@property (weak, nonatomic) IBOutlet UIView* view;
When writing view.window inside one of myViewController.m methods, Xcode marks that line as an error with "property 'window' not found on object of type view". It fails to build. Note I originally chose the views backing class view.h as the type. I already clean ed the project.
Specifically I get the error here:
- (void)viewDidLoad
{
[super viewDidLoad];
displayLink = [view.window.screen displayLinkWithTarget:(self) selector:@selector(drawFrame)];
}
How can I resolve this? I like to access the view controllers views window inside one of the view controllers methods.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@synthesize 语句是什么?
不要将插座命名为“view”,这会导致与具有 view 属性的 UIViewController 混淆。
目前,Apple 默认使 iOS IBOutlets 变弱。自早期的 iOS SDK 以来,这种情况已经发生了变化。如果 IBOutlet 由超级视图或控制器保留,那么它们通常会起作用。
What is the @synthesize statement?
Don't name an outlet "view", that causes confusion with UIViewController that has a view property.
Currently Apple defaults to making iOS IBOutlets weak. This has changed since the early iOS SDKs. IBOutlets that are weak will generally work if they are retained by a super view or controller.