<分区>
我的问题是当 FirstViewController 中的一个 SecondViewController 实例为变量 ID 赋值时,问题是我无法使用 Segue 和 NaviagtioController.. 也许解决方案使用静态变量?如何实现,或告诉我提示?
我这样做代码:
// In the class FirstViewController.m
#import "SecondViewController"
NSString *identifier = [NSString stringWithFormat:@"%@", [self.cat objectAtIndex:indexPath.row]];
// Start the code causes an error
ViewControllerOne *instance = [[ViewControllerOne alloc]init];
instance.ID = [[NSString alloc] initWithFormat:@"%@",identifier];
// End code causes error
// In the SecondViewController.h
@property (nonatomic, retain) NSString *ID;
// In the SecondViewController.m
@synthesize ID;
调试错误:
2013-05-03 09:01:42.126 TheFreeApp[19880:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter' * First throw call stack: (0x1cbc012 0x10f9e7e 0x1cbbdeb 0x53d748 0x558b1b 0x558646 0x11eff8 0x11f232 0x5588d5 0xbf5b 0x11ce1e 0xb74e 0xed285 0xed4ed 0xaf75b3 0x1c7b376 0x1c7ae06 0x1c62a82 0x1c61f44 0x1c61e1b 0x1c167e3 0x1c16668 0x3dffc 0x2bcd 0x2af5) libc++abi.dylib: terminate called throwing an exception (lldb)
最佳答案
试试这个
[[NSUserDefaults standardUserDefaults]setValue:yourVal forKey:@"myValue"];
NSString *myVal = [[NSUserDefaults standardUserDefaults]valueForKey:@"myValue"];
希望对你有帮助
关于iphone - 如何在不使用 segues 和 NaviagationController 的情况下在两个 ViewController 之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16353543/