我正在制作我的第一个OSX应用程序。我的appDelegate有一个contentView为NSViewController的窗口。此NSViewController具有在启动时显示的自定义视图。我添加了一个NSScrollView作为NSViewController的属性,在xib中我将它放在正确的位置,并将其引用给文件所有者( NSViewController)。在显示视图时,scrollView从不显示。包含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在viewController的.m中:
#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如果有人能帮上忙,那就太棒了!谢谢!
发布于 2013-01-19 05:27:47
如果我理解您的问题,如果scrollView1与xib文件连接良好,则不需要分配/初始化它。xib为您分配它,因为scrollView1是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。希望它能帮上忙!
https://stackoverflow.com/questions/14394790
复制相似问题