setImage-addSubview-发布

发布于 2024-10-21 04:43:17 字数 633 浏览 6 评论 0原文

以下是 iPhone 的一些代码:

Controller.h:

IBOutlet UIImageView *userImage;
IBOutlet UIImageView *userImage2;

}
@property (nonatomic, retain) IBOutlet UIImageView *userImage;
@property (nonatomic, retain) IBOutlet UIImageView *userImage2;

Controller.m:

UIImageView *myImage2b = [[UIImageView alloc] initWithFrame:myImageRect4];
[myImage2b setImage:[UIImage imageNamed:@"RedPin.png"]];
[userImage2 addSubview:myImage2b];

[userImage2 release];
[myImage2b release];

我只是想从我的子视图中删除“RedPin”并重新使用 userImage2 作为将来的引脚。当然,发布后userImage2就无法访问了。这不是地图应用程序。任何想法都会有帮助。提前致谢。

Here is some code for iPhone:

Controller.h:

IBOutlet UIImageView *userImage;
IBOutlet UIImageView *userImage2;

}
@property (nonatomic, retain) IBOutlet UIImageView *userImage;
@property (nonatomic, retain) IBOutlet UIImageView *userImage2;

Controller.m:

UIImageView *myImage2b = [[UIImageView alloc] initWithFrame:myImageRect4];
[myImage2b setImage:[UIImage imageNamed:@"RedPin.png"]];
[userImage2 addSubview:myImage2b];

[userImage2 release];
[myImage2b release];

I am just trying to get rid of the "RedPin" from my Subview and re-use userImage2 for future pins. Of course, userImage2 is not accessible after the release. This is not a mapping app. Any ideas would be helpful. Thanks in advance.

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

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

发布评论

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

评论(1

空城之時有危險 2024-10-28 04:43:17

我要做的就是在你的头文件中声明 userImage2 ,就像你一样。然后,无需在初始化后释放它,只需将其添加

[userImage2 release]

到您的 dealloc 函数中,并

[userImage2 removeFromSuperview]

在您想从视图中删除图像时调用。

编辑:我似乎有点误读了你的帖子。如果您只想从 userImage2 中删除红色图钉,请使用:

[[userImage2.subviews objectAtIndex:0] removeFromSuperview]

What I would do is declare userImage2 in your header file., like you have. And then instead of releasing it after initializing it simply add the

[userImage2 release]

to your dealloc function and call

[userImage2 removeFromSuperview]

whenever you want to remove the image from the view.

EDIT: I seem to have misread your post slightly. If you want to remove just the red pin from userImage2 use:

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