【发布时间】:2013-04-21 12:39:31
【问题描述】:
我正在使用 Storyboards,并且我创建了一个 UIScrollView 及其插座:
.h
@interface ViewController : UIViewController <UIScrollViewDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@end
.m:我合成了scrollView,在viewDidLoad上我有
- (void)viewDidLoad {
[super viewDidLoad];
self.scrollView.delegate = self;
// Init an array with 3 images
subviewArray = [[NSMutableArray alloc] initWithObjects:@"image1.jpg", @"image2.jpg", @"image3.jpg", nil];
for (int i = 0; i < [subviewArray count]; i++) {
//We'll create a View object in every 'page' of our scrollView.
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = [UIImage imageNamed:[subviewArray objectAtIndex:i]];
[self.scrollView addSubview:imageView];
}
NSLog(@"%f", self.scrollView.frame.size.width);
//Set the content size of our scrollview according to the total width of our imageView objects.
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [subviewArray count], self.scrollView.frame.size.height);
}
问题是当我打印“self.scrollView.frame.size.width”的值时,我得到“0”! 任何帮助请 !!!
【问题讨论】:
-
您是否将滚动视图连接到插座? self.scrollView 是 nil 吗?
-
我确实做到了,当我不使用情节提要时,它使用相同的逻辑工作!
-
您验证了实例实际上是在运行时设置的?
-
我还应该问一下您是如何从情节提要中创建视图控制器的。
-
是的,实例是在运行时设置的
标签: ios uiscrollview storyboard