0

私の問題は、変数 ID に値を割り当てるための FirstViewController の SecondViewController のインスタンスの場合です。問題は、Segue と NaviagioController を使用できないことです。おそらく、解決策は静的変数を使用しますか?、どうすればよいですか、またはヒントを教えてください。

私はそれをこのコードで行います:

// 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] * キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了します。 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)

4

2 に答える 2

3

これを試して

[[NSUserDefaults standardUserDefaults]setValue:yourVal forKey:@"myValue"];
NSString *myVal = [[NSUserDefaults standardUserDefaults]valueForKey:@"myValue"];

私が助けてくれることを願っています

于 2013-05-03T07:14:44.357 に答える