如果我创建一个UIImageViewvia Storyboard 并将其作为 a 添加@property到 aViewController.h中,我可以UIImageView从ViewController.mvia[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,我似乎无法访问它。有谁知道我做错了什么?