将图像分配给 UIImageView 引起的奇怪错误
我正在开发一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正在
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:
andviewDidDisappear:
. Consequently, when you dismiss the image picker, your view is sentviewWillAppear:
andviewDidAppear:
.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
.