UIImageView /UIImage 不工作 - 我做错了什么?

发布于 2024-11-14 09:51:05 字数 1400 浏览 3 评论 0原文

我的形象没有发挥作用。谁能告诉我我在这里做错了什么?

musclePicture 是一个字符串,格式为 picture.png

第一个视图:

NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
specificExerciseTableViewController.muscleImage = [UIImage imageNamed:muscleURL]; 

第二个视图:

detailViewController.muscleImage = self.muscleImage;

第三个视图:

self.image = [[UIImageView alloc]initWithImage:muscleImage];
[image release];

编辑:

MusclesTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
    specificExerciseTableViewController.muscleImage = [UIImage imageNamed:muscleURL]; 
}

SpecificExerciseTableViewController.h
@property (nonatomic, retain) UIImage *muscleImage;

SpecificExerciseTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    detailViewController.muscleImage = self.muscleImage;
}

DetailViewController.h
@property (nonatomic, retain) UIImage *muscleImage;
@property (nonatomic, retain) IBOutlet UIImageView *image;

DetailViewController.m
- (void)viewDidLoad
{
    self.image.image = muscleImage;
}

I am not getting my image working. Can anyone tell me what I am doing wrong here?

musclePicture is a string in format of picture.png

1st view:

NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
specificExerciseTableViewController.muscleImage = [UIImage imageNamed:muscleURL]; 

2nd view:

detailViewController.muscleImage = self.muscleImage;

3rd view:

self.image = [[UIImageView alloc]initWithImage:muscleImage];
[image release];

Edit:

MusclesTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
    specificExerciseTableViewController.muscleImage = [UIImage imageNamed:muscleURL]; 
}

SpecificExerciseTableViewController.h
@property (nonatomic, retain) UIImage *muscleImage;

SpecificExerciseTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    detailViewController.muscleImage = self.muscleImage;
}

DetailViewController.h
@property (nonatomic, retain) UIImage *muscleImage;
@property (nonatomic, retain) IBOutlet UIImageView *image;

DetailViewController.m
- (void)viewDidLoad
{
    self.image.image = muscleImage;
}

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

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

发布评论

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

评论(3

云裳 2024-11-21 09:51:05

尝试在以下之后给你的 UIImageView 一个框架:

self.image = [[UIImageView alloc]initWithImage:muscleImage];
[image setFrame:CGRectMake(0,0,50,50)];
[image release];

Try by giving a frame to your UIImageView after:

self.image = [[UIImageView alloc]initWithImage:muscleImage];
[image setFrame:CGRectMake(0,0,50,50)];
[image release];
↘紸啶 2024-11-21 09:51:05

尝试以下代码片段:

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[animal imageURL]]];
UIImage *animalImage = [[UIImage alloc] initWithData:imageData];

将其分配给您的 UIImageViewUIImage

Try this code snippet:

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[animal imageURL]]];
UIImage *animalImage = [[UIImage alloc] initWithData:imageData];

Assign it your UIImageView or UIImage.

金兰素衣 2024-11-21 09:51:05

我认为您忘记将图像作为 subView 添加到您的视图中。

像这样

[self.view addSubView:image];

,或者您有一个作为 IBOutlet 连接到 .xib 文件的类变量,并且您正在使用 alloc重新初始化它>init,如果是这种情况那么你必须这样做

self.image.image = [UIImage imageNamed: muscleImage];

I think you forgot to add image as subView to your view.

like this

[self.view addSubView:image];

or you are having a class variable that is connected to .xib file as an IBOutlet and you are reinitializing it using alloc and init, if that is the case then you have to do

self.image.image = [UIImage imageNamed: muscleImage];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文