简体   繁体   中英

BOOL property on UIViewController changes on its own

On viewController AI have a BOOL property wantsAsk set on it (nonatomic, assign) that I access by self.wantsAsk. When I segue to another view controller (vcB) I set its wantsAsk to the same as vcA. When it is time to return to A, vcB's prepareToSegue method is called and I get a pointer to vcA from the seque (segue.destinationViewController); but it shows the values of vcA all wrong. In particular, wantsAsk which should be (and was) YES is now NO.

I've tried to set a watchPoint on wantsAsk but it is never triggered. I use this general device all the time, and wonder why it could be failing here.

If you are segueing back to your view controller A you are most likely reinstantiating it. So the new A view controller is different from the your original A view controller.

Instead, just skip prepare for segue from B to A. If you are using a navigation controller, let it take care of returning to A. If B is modal, just call dismissViewController .

Provided that you only use the setter methods for your property (ie you do NOT use _wantsAsk =, or whatever your synthesize'd var is) You can figure out exactly where it gets set by using a symbolic breakpoint. Go to the breakpoints window and click on a symbolic breakpoint or using the default Xcode shortcuts press cmd+opt+\\ From there, add "setWantsAsk:" (without quotes). Run the program and check out the places where it stops.

符号调试

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