UIImageView /UIImage 不工作 - 我做错了什么?
我的形象没有发挥作用。谁能告诉我我在这里做错了什么?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在以下之后给你的 UIImageView 一个框架:
Try by giving a frame to your UIImageView after:
尝试以下代码片段:
将其分配给您的
UIImageView
或UIImage
。Try this code snippet:
Assign it your
UIImageView
orUIImage
.我认为您忘记将图像作为
subView
添加到您的视图中。像这样
,或者您有一个作为
IBOutlet
连接到.xib
文件的类变量,并且您正在使用alloc
和重新初始化它>init
,如果是这种情况那么你必须这样做I think you forgot to add image as
subView
to your view.like this
or you are having a class variable that is connected to
.xib
file as anIBOutlet
and you are reinitializing it usingalloc
andinit
, if that is the case then you have to do