Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 NSViewController中的NSScrollView_Objective C_Macos_Subview_Nsscrollview_Nsviewcontroller - Fatal编程技术网

Objective c NSViewController中的NSScrollView

Objective c NSViewController中的NSScrollView,objective-c,macos,subview,nsscrollview,nsviewcontroller,Objective C,Macos,Subview,Nsscrollview,Nsviewcontroller,我正在制作我的第一个OSX应用程序。我的appDelegate有一个窗口,其中包含NSViewController的contentView。此NSViewController有一个在启动时显示的自定义视图。我添加了一个NSScrollView作为我的NSViewController的属性,并在xib中将其放置在正确的位置,并将其引用给文件所有者(NSViewController)。显示视图时,滚动视图从不显示。包含scrollView的代码如下所示: 在viewController的.h中: #

我正在制作我的第一个OSX应用程序。我的appDelegate有一个窗口,其中包含NSViewController的contentView。此NSViewController有一个在启动时显示的自定义视图。我添加了一个NSScrollView作为我的NSViewController的属性,并在xib中将其放置在正确的位置,并将其引用给文件所有者(NSViewController)。显示视图时,滚动视图从不显示。包含scrollView的代码如下所示:

在viewController的.h中:

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import "StockData.h"
@interface MasterViewController : NSViewController {

IBOutlet NSScrollView * scrollView1;
}
@property (retain) IBOutlet NSScrollView * scrollView1;
@property (retain) NSView * contents;

@end
#import "MasterViewController.h"
#import <math.h>
#import <Foundation/Foundation.h>

@implementation MasterViewController
@synthesize scrollView1, contents;

- (void) awakeFromNib
{
self.scrollView1 = [[NSScrollView alloc] init];
self.contents = [[NSView alloc] initWithFrame:NSMakeRect(0,0,430,1000)]; 
[self.view addSubview:scrollView1];
[self.scrollView1 setDocumentView:self.contents];
}

@end
#导入
#进口
#导入“StockData.h”
@界面MasterViewController:NSViewController{
IBS滚动视图*滚动视图1;
}
@属性(保留)IBMScrollView*scrollView1;
@属性(保留)NSView*内容;
@结束
在viewController的.m中:

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import "StockData.h"
@interface MasterViewController : NSViewController {

IBOutlet NSScrollView * scrollView1;
}
@property (retain) IBOutlet NSScrollView * scrollView1;
@property (retain) NSView * contents;

@end
#import "MasterViewController.h"
#import <math.h>
#import <Foundation/Foundation.h>

@implementation MasterViewController
@synthesize scrollView1, contents;

- (void) awakeFromNib
{
self.scrollView1 = [[NSScrollView alloc] init];
self.contents = [[NSView alloc] initWithFrame:NSMakeRect(0,0,430,1000)]; 
[self.view addSubview:scrollView1];
[self.scrollView1 setDocumentView:self.contents];
}

@end
#导入“MasterViewController.h”
#进口
#进口
@主视图控制器的实现
@综合视图1,内容;
-(无效)从NIB中唤醒
{
self.scrollView1=[[NSScrollView alloc]init];
self.contents=[[NSView alloc]initWithFrame:NSMakeRect(0,04301000)];
[self.view addSubview:scrollView1];
[self.scrollview 1 setDocumentView:self.contents];
}
@结束

如果有人能帮忙,那就太棒了!谢谢

如果我理解您的问题,那么如果scrollView1与xib文件连接良好,则不需要分配/初始化scrollView1。由于scrollView1是xib的一个对象,所以xib将其分配给用户。如果在分配之前和之后
NSLog(@“%@,[scrollView1 description])
,它应该为您提供两个不同的对象。我会尝试:

self.contents = [[NSView alloc] initWithFrame:NSMakeRect(0,0,430,1000)]; 
[self.view addSubview:scrollView1];
[self.scrollView1 setDocumentView:self.contents];
现在您正在将xib scrollView1对象添加到self.view中。
希望有帮助

对scrollView使用
initWithFrame
而不是
init
,或者使用子视图自动调整大小。我尝试了这两种方法,但均无效:(