Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在NSView子类中添加子视图(WebView)_Objective C_Cocoa_Nsview - Fatal编程技术网

Objective c 在NSView子类中添加子视图(WebView)

Objective c 在NSView子类中添加子视图(WebView),objective-c,cocoa,nsview,Objective C,Cocoa,Nsview,好的,这个场景非常简单,但是-因为NSViews从来都不是我的强项-我决定寻求一些帮助 所以 我们有一个NSView子类 创建NSView时,我们希望添加一个子视图(WebView),该子视图将占用所有初始视图的空间并自动调整宽度/高度 这是我的代码(如上所述,它仍然不起作用): 有什么想法吗?问题是什么? - (id) initWithFrame:(NSRect)frame { NSLog(@"In INIT"); self = [super initWithFrame:

好的,这个场景非常简单,但是-因为
NSView
s从来都不是我的强项-我决定寻求一些帮助

所以

  • 我们有一个
    NSView
    子类
  • 创建
    NSView
    时,我们希望添加一个子视图(
    WebView
    ),该子视图将占用所有初始视图的空间并自动调整宽度/高度
这是我的代码(如上所述,它仍然不起作用):


有什么想法吗?

问题是什么?
- (id) initWithFrame:(NSRect)frame {

    NSLog(@"In INIT");
    self = [super initWithFrame:frame];
    if (self == nil) return nil;

    [self setWebView:[[WebView alloc] initWithFrame:frame]];
    [[self webView] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"index" 
                                                     ofType:@"html"];

    NSString *htmlContent = [NSString stringWithContentsOfFile:path     
                                                      encoding:NSUTF8StringEncoding 
                                                         error:nil];

    [[[self webView] mainFrame] loadHTMLString:htmlContent 
                                       baseURL:[NSURL URLWithString:path]];

    [self addSubview:[self webView]];

    return self;
}