简体   繁体   English

UIImageView更改问题iPhone问题

[英]UIImageView Changing Issue IPhone Issue

I am trying to make a button in my IPhone app which changes an existing image (simple, I know! but I've spent 2 days on this :) 我正在尝试在iPhone应用程序中创建一个按钮来更改现有图像(很简单,我知道!但是我已经花了2天的时间了:)

I have a button: 我有一个按钮:

- (IBAction)myButton {  
    myUIImageView.image = [UIImage imageNamed:@"image.jpg"];
    NSLog(@"my button");
}

I am attempting to find out why the button is not doing anything. 我试图找出为什么按钮没有执行任何操作。 "my button" does get logged to the console so I know its mapped correctly. “我的按钮”确实已登录到控制台,因此我知道其正确映射。 Firstly, I was hoping someone could tell me if I could perhaps log some more important info here, like the image file path? 首先,我希望有人可以告诉我是否可以在这里记录一些更重要的信息,例如图像文件路径? Or perhaps you see why this isn't working. 也许您知道为什么这行不通。

I synthesize myUIImageView above this: 我在上面合成myUIImageView:

@synthesize myUIImageView;

And I declare it in my .h file: 我在.h文件中声明了它:

- (IBAction)myButton;
    @property(retain, nonatomic) IBOutlet UIImageView* myUIImageView;

Typically, something is nil here. 通常,这里没有东西。

You have 你有

myUIImageView.image = [UIImage imageNamed:@"image.jpg"];

So the obvious suspects would be either: 因此,明显的怀疑者可能是:

  1. myUIImageView is nil, or myUIImageView为nil,或
  2. [UIImage imagedNamed:@"image.jpg"] is returning nil. [UIImage imagedNamed:@“ image.jpg”]返回nil。

Add some logging to see if either of those is true. 添加一些日志记录以查看其中一个是否正确。

NSLog(@"imageView: %@, image resource: %@", myUIImageView, [UIImage imageNamed:@"image.jpg"]);

If the image isn't being loaded, then I would expect for you to see a change in the UI, so that's probably not the issue. 如果未加载图像,那么我希望您能看到UI发生更改,因此这可能不是问题。

More likely is that the nib outlet for myUIImageView haven't been wired up correctly in Interface Builder, but the logging should point you in the right direction. 很有可能是myUIImageView的笔尖出口没有在Interface Builder中正确连接,但是日志记录应该为您指明正确的方向。

Two things to try: 尝试两件事:

  1. Make sure that your UIImageView is actually being displayed. 确保您的UIImageView实际上正在显示。 Do do this, just set its background color to something visible, eg, myUIImageView.backgroundColor = [UIColor redColor]; 为此,只需将其背景色设置为可见的颜色即可,例如, myUIImageView.backgroundColor = [UIColor redColor]; .
  2. Make sure that your image file ("image.jpg") is part of your project. 确保您的图像文件(“ image.jpg”)是项目的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM