2014-07-10 38 views
-2

我已經從示例項目中複製下面的代碼,但收到警告「格式字符串未使用數據參數」。在我從中複製的項目中,它在每個報價/條目的末尾添加了一個隨機數。我不需要這個,並且想象這與它有關。編譯器警告:格式字符串不使用數據參數

任何人都可以告訴我如何解決?

dvent

(IBAction)button:(id)sender { 
int r = arc4random() % 2; 
NSString *text; 
switch (r) { 
    case 1: 
     text = [NSString stringWithFormat: @"The rain in spain falls mainly on the plain", r]; 
     break; 
    case 2: 
     text = [NSString stringWithFormat: @"I think therefore I am", r]; 
     break; 
} 
self.label.text = text; 
+1

這與Xcode無關。 –

+2

閱讀錯誤。然後看看你對'stringWithFormat:'的調用。這很清楚。 – rmaddy

+1

另外,*閱讀該方法的文檔*。 –

回答

2

如果你不想字符串與r格式化,然後簡單地做:

- (IBAction)button:(id)sender { 
    int r = arc4random() % 2; 
    NSString *text; 
    switch (r) { 
     case 1: 
      text = @"The rain in spain falls mainly on the plain"; 
      break; 
     case 2: 
      text = @"I think therefore I am"; 
      break; 

    } 
    self.label.text = text; 
} 

僅使用stringWithFormat:當你真正需要格式化字符串。

+0

謝謝rmaddy。我對這一切都很陌生! – dvent

相關問題