2014-01-12 60 views
-2

在這種瓦利德我創建一個Android應用程序,我想表明從MySQL到目標下,我是用下面的PHP中的數據是我的代碼目標C和PHP互動

+(NSDictionary*) callWebservice : (NSString*)url 
{ 
NSDictionary *dictionary = nil; 
Reachability *reachability = [Reachability reachabilityForInternetConnection]; 
NetworkStatus networkStatus = [reachability currentReachabilityStatus]; 

if (networkStatus == NotReachable) { 
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle(angry)"" message:@"Connection not available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    [alert show]; 
} 
else 
{ 

    if (url!=nil && ![url isEqualToString:@""]) { 
     NSLog(@"URl : %@",url); 
     NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; 

     NSError *error = nil; 
     NSString *resultData = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
     dictionary = [[[SBJSON alloc] init] objectWithString:resultData error:&error]; 

     if (dictionary == nil) 
     { 

      NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; 

      NSError *error = nil; 
      NSString *resultData = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
      dictionary = [[[SBJSON alloc] init] objectWithString:resultData error:&error]; 

     } 
    } 
} 
return dictionary; 

現在我有在我這樣的

NSLog(@"data is == %@",[Webservice callWebservice:@"http://geekdev786.com/apilive/UserAccount.php?task=GasCompressor&uid=201&page=5"]); 

視圖控制器打電話給它,它給我的控制檯JSON數組現在我想將其保存在數組中,並顯示在表請幫

+0

爲什麼下降投票? – user3089900

回答

-1

一個聲明屬性NSDictionary(也許dataForTable)。並假設該表格被稱爲tableNeedingData

viewDidLoadviewDidAppear,你會希望這樣的事情...

self.dataForTable = [Webservice callWebservice:@"http://oilbaronapp.com/apilive/UserAccount.php?task=GasCompressor&uid=201&page=5"]; 
// This takes the results of the [Webservice callWebservice:] call and saves it to self.dataForTable 

[self.tableNeedingData reloadData]; 
// This may or may not be necessary depending on when/where you're implementing this 
// This just tells the table to refresh itself now that you're certain that self.dataForTable has the data you want to display. 
在你的表數據源的方法

現在,只需將手伸入self.dataForTable將您的所有信息。

例如,

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [self.dataForTable count]; 
} 
+0

還有一件事你能告訴我如何發佈? – user3089900

+0

發佈什麼?如果您對如何使用'UITableView'有疑問,我建議您查看關於該主題或官方文檔的其他問題。 – nhgrif

+0

什麼是datafortable它是nsdictonery? – user3089900