当我尝试加载另一个视图时,我收到此错误:
2012-02-21 20:31:38.477 App Demo[1671:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'
我无法确切地找到错误的位置。
任何帮助?
更新
NSString *pn1 = player1name.text;
NSString *pn2 = player2name.text;
NSString *pn3 = player3name.text;
NSString *pn4 = player4name.text;
NSString *k = kingdomLevel.text;
Kscores *kscores = [[Kscores alloc] initWithNibName:nil bundle:nil];
kscores.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:kscores animated:YES];
[[kscores player1name] setText:[NSString stringWithString:(NSString *)pn1]];
[[kscores player2name] setText:[NSString stringWithString:(NSString *)pn2]];
[[kscores player3name] setText:[NSString stringWithString:(NSString *)pn3]];
[[kscores player4name] setText:[NSString stringWithString:(NSString *)pn4]];
[[kscores king] setText:[NSString stringWithString:(NSString *)k]];
断点停在此代码
[[kscores player1name] setText:[NSString stringWithString:(NSString *)pn1]];
答案 0 :(得分:5)
做stringWithString:
的重点是什么?您可以像[[kscores player1name] setText:pn1];
您收到错误是因为pn1
为零,并且您无法将nil传递给stringWithString:
。
答案 1 :(得分:1)
这意味着行中的pn1
为nil
:
[[kscores player1name] setText:[NSString stringWithString:(NSString *)pn1]];
这意味着该行中的player1name
或player1name.text
为nil
:
NSString *pn1 = player1name.text;
答案 2 :(得分:0)
您正在尝试传递 nil 参数:[[kscores player1name] setText:nil];
,因为[NSString stringWithString:(NSString *)pn1]
NULL 。
相反,请尝试:[[kscores player1name] setText: pn1]