2011-08-11 71 views
2

我在我的.h文件中聲明的方法爲警告對buttonPressed方法

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

它顯示我警告likd「格式的字符串不是字符串字面量(潛在不安全」

PLS建議我什麼我應該做的......

+0

可能重複[發出帶有編號:格式字符串不是一個字符串文字(HTTP://計算器.com/questions/5428325/issue-with-code-format-string-is-a-string-literal) – highlycaffeinated

回答

1

你應該給的數據類型的參考。你要顯示的消息,這是字符串類型,所以你應該寫這樣下面的代碼:

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

thanx its working – iPhone

3

你沒有指定格式字符串:

NSLog(@"%@", themessage); 

的如何使用功能上CocoaDev一些有用的例子

1

試試這個:

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

嘗試通過alloc分配字符串對象後。

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]]); 
} 
1

嘗試這個..

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

}

+0

thanx for answer – iPhone