正如您在图 block 中看到的那样,我尝试在两个 View 之间共享一个变量(所选对象的 ID)。 我该怎么办?
这是我在其他 View 上的代码:
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];
在我的另一个 View 中我需要哪些代码来获取这个变量?
最佳答案
EditProd 应该有一个公共(public)属性,例如
@property bool myBooleanVariable;
然后只需从 view1 更改它,例如
EditProd *edit = [[EditProd alloc] initWithNibName:@"EditProd" bundle:[NSBundle mainBundle]];
edit.myBooleanVariable = false;
[self.navigationController pushViewController:edit animated:YES];
[edit release];
关于objective-c - 如何在 iOS 中的两个 View 之间传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8297527/