我在我的应用程序中使用基于导航的视图控制器。用户可以单击导航中的按钮打开一个新视图,在其中可以从几个不同的选项中进行选择。我希望发生的是,当用户返回到原始视图时,应用程序会将第二个视图中选择的选项保存在原始视图中的对象中。
我尝试了一些方法,但没有一个起作用。
我尝试在原始视图控制器中创建一个对象,将其转换为属性:
@property (nonatomic, retain) NSString *testing;
然后在第二个视图控制器中,当用户选择一个选项时用类似的内容更新它:
if (!oVC)
oVC = [[OriginalViewController alloc] init];
oVC.testing = object;
我无法让它工作。有人能指出我正确的方向吗?我们将不胜感激。
I'm using a navigation based view controller in my app. Users can click on a button in the navigation to open a new view where they can select from a few different options. What I'd like to happen is when the user returns to the original view, the app saves the option chosen in the second view in an object in the original view.
I've tried a few things but none of them work.
I've tried creating an object in the original view controller, turning it into a property:
@property (nonatomic, retain) NSString *testing;
then in the second view controller, updating it with something like this when the user selects an option:
if (!oVC)
oVC = [[OriginalViewController alloc] init];
oVC.testing = object;
I can't get it to work. Could someone point me in the right direction? It would be greatly appreciated.
发布评论
评论(1)
使用 NSUserDefaults
在一个类中:
在另一类中:
检查 文档在这里!
您还可以拥有 NSNotification 并传递 NSDictionary 类型:
然后您可以添加观察者并为相应的 Selector 编写方法。
Use NSUserDefaults
In one class:
In another class:
Check for the Documentation here !
You could also have NSNotification and pass an NSDictionary type:
And then you could add observers and write the method for the corresponding Selector.