2011-04-04 90 views
0

在Xcode中找不到编译问题时遇到问题。我得到的错误是Expected ']' before ';' token丢失方括号问题

你能帮我找到问题吗?

这是在执行文件的方法:

- (IBAction) sendButtonTapped:(id)sender 
{ 
    NSString* themessage = [NSString stringWithFormat:@"I'm %@ and feeling %@ about it.", 
           [activities objectAtIndex:[tweetPicker selectedRowInComponent:0]]; 
    [feelings objectAtIndex:[tweetPicker selectedRowInComponent:1]]]; 
    NSLog(themessage); 
} 

提前感谢!

回答

4

你有';'在第二行应该是':

NSString* themessage = 
     [NSString stringWithFormat:@"I'm %@ and feeling %@ about it.", 
       [activities objectAtIndex:[tweetPicker selectedRowInComponent:0]], 
       [feelings objectAtIndex:[tweetPicker selectedRowInComponent:1]] 
     ]; 
2

(1)derp。另一个人说什么; (2)不要直接将字符串传递给NSLog();否则,将不会将字符串直接传递给NSLog();否则,将不会将字符串直接传递给NSLog()。如果您只想记录一个字符串,请执行NSLog(@"%@", aString);

+0

你能解释为什么(2)? – DMan 2011-04-04 23:30:01

+0

当然 - “NSLog()”的第一个参数是格式字符串。任何包含的'%'序列都将被解释。尝试打印'NSLog(@“%@%@%@”)';它会崩溃。如果你的字符串碰巧有任何随机的'%'序列,它会导致类似的崩溃。 – bbum 2011-04-05 00:03:51