[英]How to retain my nsstring when popping to another view controller
I am trying make an NSString retain its value in another view controller, and it works when I push to the viewcontroller controller. 我正在尝试使NSString在另一个视图控制器中保留其值,并且当我推送到viewcontroller控制器时它可以工作。 However when I use the apple's navigation back button (automatically generated) it doesn't retain the value.
但是,当我使用苹果的导航后退按钮(自动生成)时,它不会保留该值。 How do I overcome this?
我该如何克服呢? I believe the automatic back button is poptoviewcontroller.
我相信自动返回按钮是poptoviewcontroller。 I will post some code to help give you an idea.
我将发布一些代码来帮助您提供一个想法。
NSString *ee = @"energy";
optViewController.energy = ee;
Controller I am trying to goto. 控制器,我试图转到。
@property (strong,nonatomic) NSString *energy
I followed this answer and it worked great: https://stackoverflow.com/a/9736559/2670912 . 我遵循了这个答案,效果很好: https : //stackoverflow.com/a/9736559/2670912 。 I found that using a protocol worked the best for me.
我发现使用协议最适合我。 And it helped me avoid rigidity.
它帮助我避免了僵化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.