如何在iOS中的两个视图之间传递变量

FAj*_*jir 0 xcode objective-c ios

正如您在磁贴中看到的,我尝试在两个视图(所选对象的id)之间共享变量.我能怎么做?

这是我的其他视图的代码:

EditProd *edit = [[EditProd alloc] initWithNibName:@"EditProd" bundle:[NSBundle mainBundle]];        
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:edit animated:YES];
[edit release];
Run Code Online (Sandbox Code Playgroud)

我在其他视图中需要哪些代码来获取此变量?

Joh*_*ann 6

EditProd应该有一个公共属性,例如

 @property bool myBooleanVariable;
Run Code Online (Sandbox Code Playgroud)

然后只需从view1更改它,例如

EditProd *edit = [[EditProd alloc] initWithNibName:@"EditProd" bundle:[NSBundle mainBundle]];        
edit.myBooleanVariable = false;
[self.navigationController pushViewController:edit animated:YES];
[edit release];
Run Code Online (Sandbox Code Playgroud)