简体   繁体   中英

IOS/Objective-C: Set property in presenting view controller

When you create a modal View Controller using code, the modal controller has the ability to access the presenting controller.

Please read following. This is the crux of question. I do not want to use delegates.

According to Apple doc s:

When you present a view controller modally (either explicitly or implicitly) using the present(_:animated:completion:) method, the view controller that was presented has this property set to the view controller that presented it.

I want to set the value of a property of the presenting view controller. However, I don't create the VC in code. I use a segue from a button.

This gives error: Property afterAdd not found on object of type UIViewController:

   self.presentingViewController.afterAdd = YES;

where the property afterAdd is set as follows:

@property (nonatomic) BOOL afterAdd;

Is there any way to set the value of a property in the presenting view controller when the link is by storyboard that is analogous to the above and does not involve using delegate methods?

You should cast self.presentingViewController to your real view controlller class. Something like this, just replace MyCustomViewController with your real controller name: ((MyCustomViewController *)self.presentingViewController).afterAdd = YES; .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM