2012-01-24 60 views
-1

我創建了一個iPad應用程序,其中我從URL中獲取數據, 當我寫這篇文章的代碼就說明我這個警告initWithContentsOfURL is deprecated警告在Xcode 4.2目標C

這裏是代碼片段,

NSString *mainstr; 

NSURL *urlr=[NSURL URLWithString:@"http://abc.com/default.aspx?id=G"]; 
NSURLRequest *reqr=[NSURLRequest requestWithURL:urlr]; 
[webViewq loadRequest:reqr]; 

mainstr=[[NSMutableString alloc]initWithContentsOfURL:urlr]; 

還的tableView它讓我看到這個警告,initWithFrame:reuseIdentifier: is deprecated

這裏是代碼片段,在我創造的每一行內一個標籤

static NSString *[email protected]"Cell"; 

if(cell == nil){ 


      cell=[[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease]; 

      CGRect frame; 
      frame.origin.x = 0; 
      frame.origin.y = 0; 
      frame.size.height = 40; 
      frame.size.width = 180; 


      UILabel *capitalLabelI = [[UILabel alloc] initWithFrame:frame]; 
      capitalLabelI.tag = CapitalTag; 
      capitalLabelI.font=[UIFont systemFontOfSize:16.0]; 

} 
capitalLabelI.text=[@" " stringByAppendingString:[a objectAtIndex:indexPath.row]]; 

return cell; 

,當我調用多個參數化的方法,它讓我看到這個警告,

方法名稱:

-(void)recentquote:(NSString *)sym:(int)i

調用了Syntex:

[self recentquote:l3:i];

警告:

Instance method '-recentquote::' not found (return type default to 'id')'

幫幫我吧!

在此先感謝!

+0

如果你給定的URL是現場,然後請刪除它,並把演示網址... – Maulik

回答

1

調用語法應該是

[self recentquote:l3 :i]; 

(注意在之間的空間),我建議反正重新命名功能。

當它說它已被棄用時,它只是意味着將來有一段時間,Apple可能會一起移除這個方法,它不再被支持。因此,改變你的

cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease]; 

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
              reuseIdentifier:CellIdentifier] autorelease]; 

Check the documentation for available style and what it means

編輯:

我建議改變它,也許到

- (void)recentQuote:(NSString *)quote withIndex:(int)index; 

然後調用它使用

[self recentQuote:@"OK" withIndex:2]; 
+0

@X斜槓,你的第二個答案是工作,但首先不工作.. – Krunal

+0

看到我的編輯,應該工作 –

2

代替

initWithContentsOfURL 

使用:

initWithContentsOfFile:encoding:error: 

initWithContentsOfFile:usedEncoding:error: 

代替

initWithFrame:reuseIdentifier: 

使用:

initWithStyle:reuseIdentifier: 

而且你應該改變的聲明:

-(void)recentquote:(NSString *)sym:(int)i 

到:

-(void)recentquote:(NSString *)sym someArg:(int)i 

好像你是真正的新的Objective-C和iPad開發,我強烈建議您閱讀:https://stackoverflow.com/questions/332039/getting-started-with-iphone-development

+0

寫什麼?裏面usedEncoding:和裏面的錯誤: – Krunal