buttonPressed方法上的警告

时间:2011-08-11 12:26:59

标签: iphone objective-c xcode

我已在我的.h文件中声明了一个方法

-(IBAction)buttonTapped:(id) sender;

我将此方法应用于我的.m文件中

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

}

但是在NSLog(themessage)行;

它向我显示警告喜欢“格式字符串不是字符串文字(可能不安全”

请告诉我应该做的事情......

6 个答案:

答案 0 :(得分:3)

您没有指定格式字符串:

NSLog(@"%@", themessage);

如何在CocoaDev上使用该功能的一些有用示例。

答案 1 :(得分:1)

试试这个:

  NSLog(@"Output : %@",themessage);

答案 2 :(得分:1)

NSLog的第一个参数应该是格式字符串,如@"I'm %@ and feeling %@",后跟%@,%d,%f等的值:

-(IBAction)buttonTapped:(id)sender
{
    NSLog( @"I'm %@ and feeling %@ about it",
           [activities objectAtIndex:[tweetPicker selectedRowInComponent:0]],
           [feelings objectAtIndex:[tweetPicker selectedRowInComponent:1]] );
}

答案 3 :(得分:1)

试试这个..

- (IBAction为)buttonTapped:(ID)发送方 {     NSString * themessage = [NSString stringWithFormat:@“我是%@并感觉%@关于它”,[activities objectAtIndex:[tweetPicker selectedRowInComponent:0]],                           [feeling objectAtIndex:[tweetPicker selectedRowInComponent:1]]];

**NSLog (@"Output = %@ ",themessage);**

}

答案 4 :(得分:1)

您必须提供数据类型的引用。您将显示消息,这是字符串的类型,因此您必须编写如下代码:

NSLog(@"Output : %@",themessage);

答案 5 :(得分:0)

在通过alloc分配字符串对象后尝试。

相关问题