如果我创建UIImageView
通过故事板,并将其添加为@property
成ViewController.h
,我可以访问UIImageView
从任何地方ViewController.m
通过[self UIImageView]
或self.UIImageView
。
但是,如果我创建了UIImageView
自编程viewDidLoad
,你看到下面,我似乎失去从外部访问的能力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;
}
所以后来如果我想修改正在显示在任意一个图像UIImageView
我从创建viewDidLoad
,我似乎无法访问。 有谁知道我做错了吗?