【问题标题】:nsview through customclass not showing通过customclass的nsview不显示
【发布时间】:2012-08-13 10:27:12
【问题描述】:

我制作了一个扩展 NSView 的 CustomView。还有一个包含 CustomView 的类 MyCLass。 在下面的代码中,CustomView viewA 正确显示。但是通过 MyClass 的相同视图不会显示。我没有错误,但屏幕上没有任何内容。有人知道为什么吗?

 CustomView* viewA = [[CustomView alloc]initWithFrame:NSMakeRect(0, 0, 600, 400)];

MyClass *foo;
[foo setFooView:[[CustomView alloc]initWithFrame:NSMakeRect(0, 0, 600, 400)]];
// or [foo setFooView:viewA];

[[self.window contentView] addSubview:viewA]; //IS SHOWING
[[self.window contentView] addSubview:foo.fooview]; //DOES NOT SHOW?

MyClass的.h文件

    #import "CustomView.h"

@interface MyClass : NSObject
{
    CustomView *fooview;
}
-(CustomView *) fooview;
-(void) setFooView:(CustomView *)input;

@end

MyClass的.m文件

    #import "MyClass.h"

@implementation MyClass

- (CustomView *)fooview {
    return fooview;
}

-(void) setFooView:(CustomView *)input
{
    fooview = input;
}

@end

【问题讨论】:

    标签: objective-c xcode4 nsview


    【解决方案1】:

    您实际上是在任何地方创建MyClass 的实例吗?看起来好像您将 CustomView 放入一个 nil 对象中。

    【讨论】:

    • 谢谢!我忘了放:MyClass *foo = [[MyClass alloc] init];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多