将委托分配给 ViewController 类

发布于 2024-12-07 01:42:26 字数 556 浏览 0 评论 0原文

遵循这个模式。

// foo.m

Bar* bar = [[Bar alloc] init];
[baz setDelegate:bar];
[bar release];

我可以在 Bar 类中调用 UIImagePicker 委托。具体来说,didFinishPickingImage。但是,我无法设置 IBOutlet UIImageView myImageView。喜欢。

// bar.m

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo

self.myImageView.image = img;

当我调试 UIImageView 时,我认为它是 nil,因为传递给 didFinishPickingImage 的 UIImage 参数也是空白的。

我的问题是,为什么?我假设我按照此示例正确设置了委托。

Following this pattern.

// foo.m

Bar* bar = [[Bar alloc] init];
[baz setDelegate:bar];
[bar release];

I'm able to call UIImagePicker Delegates in the Bar Class. Specifically, didFinishPickingImage. However, I'm not able to set my the IBOutlet UIImageView myImageView. like.

// bar.m

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo

self.myImageView.image = img;

When I debug UIImageView, it's nil I think because the UIImage param passed to didFinishPickingImage is also blank.

My question is, why? I am assuming I set my delegate correctly as per this example.

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

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

发布评论

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

评论(2

活雷疯 2024-12-14 01:42:26

您不能将 UIImageView 分配给 UIImage。这可能效果更好:

self.myImageView.image = img;

You can't assign a UIImageView to a UIImage. This might work better:

self.myImageView.image = img;
眼泪淡了忧伤 2024-12-14 01:42:26

您实际上是为“myImageView”分配内存吗?它没有显示。这不是自动的,需要 myImageView = [[UIImageView alloc] init];

Are you actually allocating memory for 'myImageView'? It isn't shown. That's not automatic, myImageView = [[UIImageView alloc] init]; would be needed

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