当我将 UIImages 用作按钮时,如何在 UIImages 上设置操作?
你好 我使用图像作为按钮,所以如何在按下时放置事件方法,我的编码如下...
UIImageView* view = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"front_pag.png"]];
view.frame = CGRectMake(0, 0, 320, 460);
[self.view addSubview:view];
new_button = [[UIButton alloc] init];
UIImage *img1 = [UIImage imageNamed:@"new.png"];
[new_button setImage:img1 forState:UIControlStateNormal];
[new_button setFrame:CGRectMake(85, 430, 0, 0)];
[new_button addTarget:self action:@selector(newMethod)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:new_button];
我应该做什么,因为在这种情况下,我无法调用 newMethod,即使我在同一个类中有这个方法。
我应该怎么办 ?
Hello
I am using images as buttons so how can I put event methods as they pressed, my coding is as below ...
UIImageView* view = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"front_pag.png"]];
view.frame = CGRectMake(0, 0, 320, 460);
[self.view addSubview:view];
new_button = [[UIButton alloc] init];
UIImage *img1 = [UIImage imageNamed:@"new.png"];
[new_button setImage:img1 forState:UIControlStateNormal];
[new_button setFrame:CGRectMake(85, 430, 0, 0)];
[new_button addTarget:self action:@selector(newMethod)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:new_button];
what should I do, because in this case, I can't call newMethod, even I have this method in same class.
what should I do ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将 addTarget 调用更改为:
注意
newMethod:
名称后面的分号这是因为您的选择器的签名应如下所示:
这样它将被调用。
祝你好运
You should change your addTarget call to this:
Pay attention to semicolon after the
newMethod:
nameThis is because the signature of your selector should be as following:
This way it will be called.
Good luck
我想你可以尝试一下这个
I think you can try this out,