Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS13 UIViewController isModalInPresentation has no setter in ObjectiveC so cannot be set?

I'm trying to make some updates to an app of mine written in ObjectiveC to adopt new iOS 13 features. I'm looking at the interactive dismissal handling of the new way of modally presenting View controllers and after detecting changes in my controller i wish to stop interactive dismissals and present a dialogue to the user as recommended by Apple. Attempting to do so with the following code

self.isModalInPresentation = YES;

doesn't compile with the following error

No setter method 'setIsModalInPresentation:' for assignment to property

Going to the implementation of this property from my ObjectiveC project goes to the ObjectiveC header with the property defined as follows

// 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));

Looking at the same property within a swift project reveals the following swift definition for it

    // 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

Is this just an oversight on Apple's part with the ObjectiveC source? I can't find any setIsModalInPresentation function or access it directly via _isModalInPresentation. It's been a while since I did any significant work in ObjectiveC so my language knowledge is rusty, am I expected to synthesize the property in my subclass? As there's already a getter implemented I'm not even sure how that would work.

I'm on Xcode 11.0, I guess I could look to see if this is fixed in later versions of Xcode/iOS?

Any help as ever is appreciated, cheers

like image 717
jimbobuk Avatar asked Dec 04 '22 18:12

jimbobuk


1 Answers

Try this:

self.modalInPresentation = YES;

As mentioned in question, it is defined as follows,

@property (nonatomic, getter=isModalInPresentation) BOOL modalInPresentation;

That means you need to set it as self.modalInPresentation = YES;. isModalInPresentation is a getter.

like image 157
adev Avatar answered May 16 '23 07:05

adev