gpt4 book ai didi

Objective-C 类型的向下转型

转载 作者:行者123 更新时间:2023-12-04 15:53:14 27 4
gpt4 key购买 nike

我正在尝试覆盖

- (void)makeWindowControllers;

这是它的代码:

NSStoryboard* const storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
NSWindowController* const windowController = [storyboard instantiateControllerWithIdentifier:@"Document Window Controller"];

然后我想将图像添加到 ViewController 用户通过 open... 在 Swift 中选择的图像我会简单地做:

(windowController.contentViewController as? ViewController)?.imageView?.image = openedImage

我如何在 Objective-C 中进行这种向下转换?我真的很困惑,因为我在学习 C 时没有做过太多类型转换。谢谢。

最佳答案

[[((ViewController *)[windowController contentViewController]) imageView] setImage: openedImage];

关于Objective-C 类型的向下转型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53020655/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com