如果您希望两个 ViewController 能够使用一个 NSObject,那么您如何知道哪个 ViewController 正在调用它,以便当您传递正在计算的数据时,将其传递回正确的 ViewController。
最佳答案
如果您希望返回的数据根据调用者而变化,请在要从中检索数据的对象中创建一个方法,而不是直接访问属性。
在您的 NSObject
中,您可以有一个遵循此格式的方法(我的示例返回一个字符串):
- (NSString *)getDataFor:(NSInteger)callingController {
NSString *outputString = nil;
if (callingController == 1) {
// set value of output string for controller 1
} else if (callingController == 2) {
// set value of output string for controller 2
}
return outputString;
}
然后,从 View Controller 中,您只需使用适当的标识符作为输入来调用该方法。
关于iphone - 如何让两个ViewController使用一个NSObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6618266/