まず、私は iOS 開発の初心者です。ScrollView で xib ファイルのビューを表示する際に問題があります。
この MyView は、1 つのラベルが付いた緑色の背景のみです。コントローラーからのコードは次のとおりです。
@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
そして、ScrollView であるメインコントローラーからのコードは次のとおりです。
- (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 (1 つのラベルを持つ緑色の背景) を表示することだけです。このアプリを実行すると、スクロールビューが空になり、中に何も表示されません。
おそらくそれはばかげた質問ですが、私が言ったように、私はこれで初心者です。私は Apple の PageControll アプリを持っていますが、これは私の iOS の初期段階では非常に複雑なコードです。もちろん、私はグーグルでした...どこが問題なのか教えてください。ありがとうございました