gpt4 book ai didi

ios - 尝试使用 UIPickerView 选择要在 UIImageView 中显示的图像

转载 作者:行者123 更新时间:2023-12-01 18:48:31 24 4
gpt4 key购买 nike

Using UIPickerView to display different images upon selection in UIImageView

因此,我正在查看这篇文章以帮助我执行与该用户相同的功能。我正在使用 PickerView 让用户在三个不同的 map 之间进行选择,并根据用户选择更改 ImageView。我在代码的以下部分遇到了麻烦

chosenFloor.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[pickerImage objectAtIndex:row]]];

它告诉我'从 UIImageView 分配给 UIImage * 的不兼容指针类型 *

有人可以解释如何将 UIImage 转换为适合 UIImageView 吗?我将在下面包含我的其余代码。我相信我已经在我的 .h 文件中正确声明了所有内容,这是用户在上述链接中遇到的问题。

Screenshot of my iOS Simulator
#import <UIKit/UIKit.h>

@interface MapViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {

IBOutlet UIPickerView *chooseFloor;
IBOutlet UIImageView *chosenFloor;
NSArray *pickerData;
}

@property (nonatomic, retain) UIPickerView *chooseFloor;
@property (nonatomic, retain) UIImageView *chosenFloor;
@property (nonatomic, retain) NSArray *pickerFloor;
@property (nonatomic, retain) NSArray *pickerImage;
//-(IBAction)performSomeAction:(id)sender;

@end

#import "MapViewController.h"

@interface MapViewController ()

@end

@implementation MapViewController

@synthesize chooseFloor;
@synthesize pickerFloor;
@synthesize chosenFloor;
@synthesize pickerImage;

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

NSArray *array = [[NSArray alloc] initWithObjects:@"Basement",
@"Main Floor",
@"Penthouse", nil];

self.pickerFloor = array;

self.chooseFloor.dataSource = self;
self.chooseFloor.delegate = self;

self.pickerImage = [[NSArray alloc] initWithObjects:@"Basement.png", @"Main.png", @"Penthouse.png", nil];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
//Determine how many columns in my pickerView
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
//Determine the number of rows in my pickerView
return [pickerFloor count];
}

//Delegate Method
//This delegate method gives us s way to retrieve the selected item from the picker view
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [pickerFloor objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

chosenFloor.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[pickerImage objectAtIndex:row]]];
}
@end

最佳答案

你在这一行是错的:

 chosenFloor.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[pickerImage objectAtIndex:row]]];
chosenFloor.imageUIImage .它应该是
chosenFloor.image = [UIImage imageNamed:[pickerImage objectAtIndex:row]];

关于ios - 尝试使用 UIPickerView 选择要在 UIImageView 中显示的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33072679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com