开发者

warning on buttonPressed method

I have declare a method in my .h file as

-(IBAction)buttonTapped:(id) sender;

and I apply this method in my .m file as

-(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);

}

but at the line NSLog (themessage);

it shows me warning likd "format 开发者_如何转开发string is not string literal(potentially unsecure"

pls suggest me what i should do...


You didn't specify a format string:

NSLog(@"%@", themessage);

Some useful examples of how to use the function on CocoaDev.


You should have to give the reference of the data type. You are going to display message and that is type of string so you should have to write like below code:

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


Try this:

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


The first parameter to NSLog should be a format string, like @"I'm %@ and feeling %@", followed by the values for %@, %d, %f, etc:

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


Try This ..

-(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 (@"Output = %@ ",themessage);**

}


Try that after allocating a string object via alloc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜