本文介绍了目标C:以编程方式创建一个UIImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让被点击时它在一个按钮的位置与巴纽一个UIImageView加载。
I'm trying to make a UIImageView with a .png load up in the location of a button when it is clicked.
brickAnim = UIImageView.alloc; ///////freezes during runtime
[brickAnim initWithFrame:currentBrick.frame];
[brickAnim setImage:[NSString stringWithFormat:@"brick-1.png"]];
[self.view addSubview:brickAnim];
当前砖
是正在的点击按钮的名称。我已经收窄,并想通了,第一行会导致应用程序冻结并退出。我想不通,我做错了什么。
current brick
is the name of the button that's being clicked. I've narrowed it down and figured out that the first line causes the app to freeze and exit. I can't figure out what I'm doing wrong.
推荐答案
尝试
brickAnim = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"brick-1.png"]];
brickAnim.frame = currentBrick.frame;
[self.view addSubview:brickAnim];
看到回应对方的回答后编辑:
edit after seeing response to other answer:
您声明和其他地方初始化brickAnim?如果没有,你需要在开始添加:
are you declaring and initializing brickAnim elsewhere? if not, you need to add at the beginning:
UIImageView *brickAnim = [[UIImageView alloc] ....;
和结尾:
[brickAnim release];
这篇关于目标C:以编程方式创建一个UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!