xCode 4.2 错误
当我尝试加载另一个视图时,出现此错误:
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]];
I'm getting this error when I try to load another view:
2012-02-21 20:31:38.477 App Demo[1671:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'
I couldn't find where is the error exactly.
Any help?
update
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]];
breakpoint stopped at this code
[[kscores player1name] setText:[NSString stringWithString:(NSString *)pn1]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这样做
stringWithString:
有什么意义?您可以直接设置它,例如[[kscores player1name] setText:pn1];
您收到错误是因为
pn1
为 nil,并且您无法将 nil 传递给stringWithString:
。What's the point of doing
stringWithString:
? You can just set it directly like[[kscores player1name] setText:pn1];
You're getting the error because
pn1
is nil, and you can't pass nil tostringWithString:
.这意味着该行中的
pn1
为nil
:这意味着
player1name
或player1name.text
为行中的 nil
:That means that
pn1
isnil
in the line:That means that
player1name
orplayer1name.text
arenil
in the line:您正在尝试传递 nil 参数:
[[kscores player1name] setText:nil];
自[NSString stringWithString:(NSString *)pn1]
为NULL。相反,请尝试以下操作:
[[kscores player1name] setText: pn1]
You are trying to pass a nil argument:
[[kscores player1name] setText:nil];
since[NSString stringWithString:(NSString *)pn1]
is NULL.Instead, try this:
[[kscores player1name] setText: pn1]