我是否必须先分配 IB 中内置的 UIView,然后才能以模态方式显示它?

发布于 2024-10-02 18:59:42 字数 628 浏览 0 评论 0原文

我有一个 UIImageView,我想加载来自 UIImagePickerController 实例的图片,以便向用户显示预览。我的应用程序有一个 TabBarViewController,为了隐藏该栏,我以模式方式显示选择器和预览。

我用于预览的控制器是在 Interface Builder 上构建的,它包含一个空的 UIImageView。拍摄照片后,我试图设置 UIImageView 的图像,但 IBOutlet 始终为零。这就是我为了实现我所寻找的目标而想到的:

[self.view addSubview:self.previewController.view];     
[self.previewController.imageView setImage:self.scaledPicture];     
[self presentModalViewController:self.previewController animated:YES];

我仍然不确定这是正确的方法,但如果我不使用上面的第一行, self.previewController.imageView 将为零。线条的视觉效果没有影响,因为模态视图涵盖了所有内容...

我多次检查了IB中的链接,它们似乎都是正确的。

这是正确的方法吗?

I have a UIImageView that I'd like to load with a picture coming from an instance of UIImagePickerController in order to show a preview to the user. My app has a TabBarViewController and in order to hide the bar I'm showing both the picker and the preview modally.

The controller I use for the preview has been built on Interface Builder and it holds an empty UIImageView. When the picture has been taken, I was trying to set the image of the UIImageView but the IBOutlet was always nil. This is what I came up to in order to achieve what I was looking for:

[self.view addSubview:self.previewController.view];     
[self.previewController.imageView setImage:self.scaledPicture];     
[self presentModalViewController:self.previewController animated:YES];

I'm still not sure this is the right approach but if I don't use the first line above, the self.previewController.imageView will be nil. The visual effect of the line has no impact because the modal view covers everything...

I checked the links in IB many times and they all appear to be correct.

Is this the right way to proceed?

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

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

发布评论

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

评论(1

九厘米的零° 2024-10-09 18:59:42

如果你刚刚创建了previewController,那么它的imageView将为nil,因为视图还没有加载。第一行似乎使它起作用的原因是它导致视图加载。

您应该做的是在 PreviewController 上有一个 image 属性,您可以在此处分配该属性。然后将图像加载到previewController的viewDidLoad中的imageView中。这样,您还可以避免查看另一个视图控制器的视图。

If you have just created previewController, then its imageView will be nil because the view has not loaded. The reason that the first line seems to make it work is because it causes the view to load.

What you should do is have an image property on the previewController which you can assign here. Then load the image into the imageView in the previewController's viewDidLoad. This way, you're also avoiding poking at another view controller's views.

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