-1
我想要繼承一個包含UIScrollView的UIView。這是我使用的代碼:爲什麼我的UIScrollView不顯示?
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}>"
)
那我做錯了嗎?
試過了,沒有工作,但謝謝。 – 2013-03-26 19:56:44