我正在尝试对我的一个用ObjectiveC编写的应用程序进行一些更新,以采用iOS 13的新功能。我正在研究以模态方式呈现视图控制器的新方法的交互式驳回处理,在检测到控制器中的更改后,我希望停止交互式驳回,并按照Apple的建议向用户呈现对话。尝试使用以下代码执行此操作
self.isModalInPresentation = YES;
无法编译,并出现以下错误
No setter method 'setIsModalInPresentation:' for assignment to property
从我的ObjectiveC项目转到此属性的实现,转到ObjectiveC标头,其中的属性定义如下
// modalInPresentation is set on the view controller when you wish to force the presentation hosting the view controller into modal behavior. When this is active, the presentation will prevent interactive dismiss and ignore events outside of the presented view controller's bounds until this is set to NO.
@property (nonatomic, getter=isModalInPresentation) BOOL modalInPresentation API_AVAILABLE(ios(13.0));
查看swift项目中的相同属性,会发现以下swift定义
// modalInPresentation is set on the view controller when you wish to force the presentation hosting the view controller into modal behavior. When this is active, the presentation will prevent interactive dismiss and ignore events outside of the presented view controller's bounds until this is set to NO.
@available(iOS 13.0, *)
open var isModalInPresentation: Bool
这仅仅是苹果对ObjectiveC源代码的疏忽吗?我找不到任何setIsModalInPresentation函数,也无法通过_isModalInPresentation直接访问它。我已经有一段时间没有在ObjectiveC中做任何有意义的工作了,所以我的语言知识已经生疏了,我需要在我的子类中合成属性吗?因为已经实现了一个getter,我甚至不确定它是如何工作的。
我使用的是Xcode11.0,我想我可以看看在Xcode/iOS的更高版本中是否修复了这个问题?
我们将一如既往地感谢任何帮助,干杯
发布于 2019-10-02 02:22:12
试试这个:
self.modalInPresentation = YES;
如上所述,它的定义如下,
@property (nonatomic, getter=isModalInPresentation) BOOL modalInPresentation;
这意味着您需要将其设置为self.modalInPresentation = YES;
。isModalInPresentation
是一个getter。
发布于 2019-10-16 01:35:44
使用API可用性检查可以很好地做到这一点!
VSDrawViewController *drawViewController = [[VSDrawViewController alloc] init];
// .. setup delegate and stuff, if needed.
if (@available(iOS 13.0, *)) {
drawViewController.modalInPresentation = YES;
} else {
// Handle old iOS changes
}
https://stackoverflow.com/questions/58190206
复制相似问题