根据 uiPickerView 以编程方式更改图像

发布于 2024-12-05 09:38:11 字数 838 浏览 3 评论 0原文

我使用 uiPickerView ,它有图像而不是字符串用于选择,可以正常显示图像,我从苹果 UIcatalog 示例中获得了关于如何放置图像的灵感,

我以编程方式实现它,没有 IB,

所以问题是,如何根据所选单元格更改图像?

我有 * MainVC(我的主视图控制器) * CustomView(定义选择器大小) * CustomPickerDataSource(选择器的数据源:)

在 CustomPickerDataSource 中,发送所选行的数据

- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
// Handle the selection
NSLog(@"seleccionokkkk: %d", row);
[MainVC entro:row];
}

,在我的 MainVC 中,

+(void) entro: (int) cuca {

NSLog(@"sumbalo :%d", cuca);
 }

我得到在 MainVC 上选择的单元格的数量,这是我想要显示不同图像的地方, 但是当在我的 +(void) entro: (int) cuca 中选择图像时 当然,当我使用类方法设置实例变量时,我会收到警告,

那么如何根据收到的单元格编号显示图像呢?

伪代码: if image == 0, show image0

在哪里放置显示代码的图像?以及如何为传入消息设置变量?

多谢!

Im using a uiPickerView that haves images instead of strings for the selections, is working ok for showing the images, I got inspiration from the apple UIcatalog example on how to put the images,

Im implementing it programatically no IB,

So the question is, how to change an image according to the selected cell?

i have
* MainVC (my main view controller)
* CustomView (defining picker size)
* CustomPickerDataSource (the data source for the picker :)

in CustomPickerDataSource, send the data for wich row was selected

- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
// Handle the selection
NSLog(@"seleccionokkkk: %d", row);
[MainVC entro:row];
}

and in my MainVC

+(void) entro: (int) cuca {

NSLog(@"sumbalo :%d", cuca);
 }

I get the number of cell selected on my MainVC, which is where I want to show the different images,
but when selecting the image in my +(void) entro: (int) cuca
I get warnings of course as Im setting instance variables with a class method,

so how can I show the image according to which cell number I receive?

Pseudocode:
if image == 0, show image0

Where to put my image showing code?, and how to set the variable for the incoming message?

thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔岸观火 2024-12-12 09:38:11

我假设您拥有的图像数量与选择器中的项目数量一样多。按照与选择器视图中相同的顺序将它们放入数组中。然后将要更改为所选图片的UIImageView,并将其设置为数组中给定索引的图片。

您可以在您的 entro: 方法中执行此操作(它应该是一个实例方法,没有理由不应该或不能),或者您可以继续在 < code>pickerView:didSelectRow: 方法。

您可以这样设置图像:

UIImageView *myImageView;
NSArray *myImageArray;
...

- (void)pickerView:(UIPickerView *)pickerView didSelectRow: 
(NSInteger)row inComponent:(NSInteger)component {
    [myImageView setImage:[myImageArray objectAtIndex:row]];
}

I'd assume you have as many images as you have items in the picker. Put them into an array in the same order as you did in the picker view. Then take the UIImageView that you want to change to the selected picture, and set it to the picture in the array with the given index.

You can do this in your entro: method (which should be an instance method, no reason that it shouldn't or can't be), or you can just go ahead and do it in the pickerView:didSelectRow: method.

You can set images like this:

UIImageView *myImageView;
NSArray *myImageArray;
...

- (void)pickerView:(UIPickerView *)pickerView didSelectRow: 
(NSInteger)row inComponent:(NSInteger)component {
    [myImageView setImage:[myImageArray objectAtIndex:row]];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文