内部に UIScrollView を含む UIView をサブクラス化しようとしています。これは私が使用しているコードです:
UIViewSubclass.h
@property (nonatomic, retain) UIScrollView *scroll;
UIViewSubclass.m
@synthesize itemScrollView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setUpScrollViewWithIdentifier:@"id"];
}
return self;
}
-(void)setUpScrollViewWithIdentifier:(NSString*)scrollViewID {
NSLog(@"Setting up Scroll View with the id of: %@",scrollViewID); //This is working
scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 90)];
//Subview of the scroll view
UIView *test = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
test.backgroundColor = [UIColor blueColor];
[scroll addSubview:test];
[self addSubview:scroll]; // Adds the scrollview to the UIView
NSLog(@"Subviews: %@",self.subviews);
}
ViewController.h
#import "UIViewSubclass.h"
IBOutlet UIViewSubclass *menuView;
Controller.m を表示
- (void)viewDidLoad
{
menuView = [[UIViewSubclass alloc]init];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
また、ビューをストーリーボードにリンクし、ビューのクラスを UIViewSubclass に設定しましたが、何らかの理由でスクロール ビューが表示されません。しかし、この NSLog を確認すると:
NSLog(@"Subviews: %@",self.subviews);
デバッガーでこれを提供します:
Subviews: (
"<UIScrollView: 0x1d5a20e0; frame = (0 0; 320 90); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1d5a2420>; layer = <CALayer: 0x1d5a1c60>; contentOffset: {0, 0}>"
)
それで、私は何を間違っていますか?