久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如果以編程方式創(chuàng)建,則無法訪問 UIImageView

Can#39;t access UIImageView if created programmatically(如果以編程方式創(chuàng)建,則無法訪問 UIImageView)
本文介紹了如果以編程方式創(chuàng)建,則無法訪問 UIImageView的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

如果我通過 Storyboard 創(chuàng)建一個(gè) UIImageView 并將其作為 @property 添加到 ViewController.h 中,我可以訪問該 UIImageViewViewController.m 中的任何位置通過 [self UIImageView]self.UIImageView.

If I create a UIImageView via Storyboard and add it as a @property into a ViewController.h, I can access that UIImageView from anywhere in the ViewController.m via [self UIImageView] or self.UIImageView.

但是如果我從 viewDidLoad 以編程方式創(chuàng)建 UIImageView,如下所示,我似乎無法從 viewDidLoad 外部訪問它.

But If I create the UIImageView programmatically from viewDidLoad as you see below, I seem to lose the ability to access it from outside 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 創(chuàng)建的任何一個(gè) UIImageView 中顯示的圖像,我似乎無法訪問它.有誰知道我做錯(cuò)了什么?

So later on if I want to modify the image that is being displayed in any one of the UIImageView I've created from viewDidLoad, I can't seem to access it. Does anyone know what I'm doing wrong?

推薦答案

你需要在你的頭文件中創(chuàng)建你的 UIImageView,然后它就可以在視圖的其余部分中使用.不過,您需要將其添加到 viewDidLoad 中的視圖中.

You would need to create your UIImageView in your header file and then it would be available throughout the rest of the view. You will need to add it to the view in viewDidLoad though.

         Header
         UIImageView *image;

         Main // ViewDidLoad
         image = [UIImageView alloc] .....
         [self.view addSubView image];


         Main Function .....
         [image setImage ....

這篇關(guān)于如果以編程方式創(chuàng)建,則無法訪問 UIImageView的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設(shè)置滾動視圖內(nèi)容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運(yùn)行時(shí),使用 iOS 6.0 SDK 并為 iOS 5 Target 構(gòu)建會導(dǎo)致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 毛片免费看的 | 午夜精品 | 国产在线观看一区二区 | 亚洲欧美激情国产综合久久久 | 久久中文免费视频 | 欧美白人做受xxxx视频 | 久久精品小短片 | 成人国产一区二区三区精品麻豆 | 欧美一区久久 | 999久久久久久久久 国产欧美在线观看 | 亚洲精品视频导航 | 精品久久国产 | 精品中文字幕一区 | 精品日韩| 日韩免费激情视频 | 色网站在线免费观看 | 91精品国产91久久久久久三级 | 国产欧美日韩综合精品一区二区 | 亚洲精品无 | 看片天堂| 一级黄色裸片 | 在线激情视频 | 精品久久一区 | 色av一区二区 | 欧美一级视频免费看 | 九九免费在线视频 | 久久久久久天堂 | 天天拍天天操 | 欧美在线观看免费观看视频 | 欧美视频在线看 | 黄色av网站在线免费观看 | 黄色av大片 | 羞羞网站在线观看 | av一区二区在线观看 | av男人的天堂在线 | 亚洲第一视频网 | 国产精品一区久久久 | av在线免费观看网站 | 亚洲成人动漫在线观看 | 欧美精品一区二区三区在线播放 | 亚洲精品一区二区在线观看 |