首先,我想说我是iOS开发的新手。我在ScrollView中显示xib文件的视图时遇到问题。在ScrollView中显示来自xib的视图
此MyView只有一个标签的绿色背景。下面是它的控制器代码:
@implementation MyView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//init code
}
return self;
}
- (id) initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
[self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
}
return self;
}
@end
,这里是从主控制器代码哪里是滚动型:
- (void)viewDidLoad
{
[super viewDidLoad];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 67, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
scroll.frame = CGRectMake(0, 20, 320, 350);
scroll.contentSize = CGSizeMake(320, 350);
scroll.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
scroll.bounces = YES;
scroll.bouncesZoom = YES;
scroll.scrollEnabled = YES;
scroll.minimumZoomScale = 0.5;
scroll.maximumZoomScale = 5.0;
scroll.delegate = self;
scroll.pagingEnabled = YES;
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
UIView *myView = [nibContents objectAtIndex:0];
myView.frame = CGRectMake(0,20,300,300);
[scroll addSubview:myView];
}
只有我想要做的事情是,我想在ScrollView中查看MyView(带有一个标签的绿色背景)。如果我运行这个应用程序,scrollview是空的,里面没有任何内容。
也许这是一个愚蠢的问题,但正如我所说,我是这个新手。我有一个来自苹果的PageControll应用程序,但对我来说,这是在我的iOS开始非常复杂的代码。当然,我是用谷歌搜索...请告诉我问题在哪里。谢谢
它是在ViewController的接口中定义的:'code' __strong IBOutlet UIScrollView * scroll; – DanielH 2013-05-09 13:55:19
所以我试图把这个代码放入viewDidLoad方法中,并且工作正常!非常感谢你! – DanielH 2013-05-09 14:00:53
非常欢迎:)您能否将我的答案标记为正确? (绿色滴答下的投票) – micantox 2013-05-09 14:01:07