将图像分配给 UIImageView 引起的奇怪错误

发布于 2024-08-09 00:09:07 字数 516 浏览 2 评论 0原文

我正在开发一个简单的 iPhone 应用程序,在某些情况下它有一个非常奇怪的行为,我无法理解...

该应用程序有一个 UIImageView 和一些控件,例如 UISwitch< /code>、标签、进度条等。这些控件最初处于某些状态,例如开关关闭、标签包含一些初始文本、进度条隐藏。这些状态最终会在与用户交互期间发生变化。

一段时间后,应用程序应该用相机拍照。这张图片将被分配给我的UIIMageView。所有对象只有一个委托控制器(为什么不呢?)。

现在问题来了:用相机拍照并将其分配给图像视图后,所有控件都返回到其初始状态...

当我注释掉一行时,图像将分配给我的 UIImageView:

imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

控件的状态不会改变!所以这只是由图像分配引起的,但为什么?!

有什么想法吗?

I'm working on a simple iPhone App and in some cases it has a very weird behavior which I just cannot understand...

The App has an UIImageView and a few controls like a UISwitch, label, progresbar etc. These control are initially in certain states, like the switch is off, the label contains some initial text, the progresbar is hidden. These states will eventually change during an interaction with user.

After a while the App should take a picture with the camera. This picture will be assigned to my UIIMageView. There is only one delegate controller for all objects (why not?).

And now comes the problem: after taking the picture with the camera and assignment of it to the image view, all controls return to their initial states...

When I comment the one line out, where the image will be assigned to my UIImageView:

imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

the states of the controls won't change! So it's caused only by the image assignment but why ?!

Any ideas?

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

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

发布评论

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

评论(1

初相遇 2024-08-16 00:09:07

听起来您正在 viewDidAppear: 中设置控件的状态。

当您显示图像选择器时,您的视图消失,并发送 viewWillDisappear:viewDidDisappear:。因此,当您关闭图像选择器时,您的视图将被发送 viewWillAppear:viewDidAppear:

如果您在该方法中设置控件的状态,那么每当调用这些方法时它们都会被重置。

也许可以考虑将代码移至 viewDidLoad 中以设置控件状态。

It sounds like you're setting the states of the controls in viewDidAppear:.

When you display the image picker, your view disappears, and is sent viewWillDisappear: and viewDidDisappear:. Consequently, when you dismiss the image picker, your view is sent viewWillAppear: and viewDidAppear:.

If you're setting the states of the controls in that method, then they'll be reset whenever those methods are called.

Maybe consider moving the code to set the control states into viewDidLoad.

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