【发布时间】:2013-01-27 06:05:19
【问题描述】:
如果我通过 Storyboard 创建 UIImageView 并将其作为 @property 添加到 ViewController.h 中,我可以从 ViewController.m 中的任何位置通过 [self UIImageView] 或 self.UIImageView 访问该 UIImageView。
但是如果我从viewDidLoad 以编程方式创建UIImageView,如下所示,我似乎无法从viewDidLoad 外部访问它。
UIImageView *prevImgView = [[UIImageView alloc] init];
UIImageView *currImgView = [[UIImageView alloc] init];
UIImageView *nextImgView = [[UIImageView alloc] init];
NSArray *imageViews = [NSArray arrayWithObjects:prevImgView, currImgView, nextImgView, nil];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview: scrollView];
CGRect cRect = scrollView.bounds;
UIImageView *cView;
for (int i=0; i<imageViews.count; i++) {
cView = [imageViews objectAtIndex:i];
cView.frame = cRect;
[scrollView addSubview:cView];
cRect.origin.x += cRect.size.width;
}
所以稍后,如果我想修改从viewDidLoad 创建的任何UIImageView 中显示的图像,我似乎无法访问它。有谁知道我做错了什么?
【问题讨论】:
标签: ios uiview uiscrollview uiimageview