2013-11-01 69 views
0

我正在使用單一類的web服務調用和顯示在uitableview中,我的功能是當我點擊提交按鈕的新的orchardname新添加然後查看重定向到tableview,但數據不是看到最近添加的。 「singOrchard.orcharsList」它是我必須展示的果園名稱數組。 「[wOrchrad getorchardslist]」這是我的web服務調用。如何顯示在按鈕點擊uitableview上的網頁json數據

- (IBAction)Submit:(id)sender 
{ 
    if (Orchadname.text.length == 0) { 
     UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"DataTree" message:@"Please Enter OrchardName" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [message show]; 
    } 
    else { 
     [singOrchard.orcharsList removeAllObjects]; 
     NSString *urlStr = [NSString stringWithFormat:@"http://xyz.com"]; // Passing token to URL 
     NSURL *url = [NSURL URLWithString:urlStr]; 
     NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 
     NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; // Support to perform URLrequest 
     if (theConnection) { // checking connection successfull or not 
      webData1 = [NSMutableData data]; 
      NSLog(@"Orchard Name is %@", Orchadname.text); 
     } 

     [wOrchrad getorchardslist]; 
     NSLog(@"ARRAY COUNT %@",singOrchard.orcharsList); 
     [self performSelector:@selector(gotodetails) withObject:nil afterDelay:4]; 
    } 
} 

「[wOrchard getorchardslist] - Singletone + Webserviceutility」

- (void)getorchardslist 
{ 
    orchardsnames = [[NSMutableArray alloc] init]; 
    singltoneclass = [SingletoneClass sharedInstanceMethod]; 
    theRequest =[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString  stringWithFormat:@"http://www.xyz.com"] 
          cachePolicy:NSURLRequestUseProtocolCachePolicy 
          timeoutInterval:60.0]; 
    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
    webData = [NSMutableData data]; 
    [theConnection start]; 
} 
+0

可以添加代碼方法[wOrchrad getorchardslist]; – suhit

+0

我添加了我的詳細信息,請檢查 – Rohan1001

回答

0

您沒有使用從theConnection返回結果。 (至少不在您提供的代碼中。)由於您已將您的類設置爲委託,請實現NSURLConnectionDataDelegate方法。

- (空)connectionDidFinishLoading:(NSURLConnection的*)連接

用它來你的JSON數據保存到一個NSArray,然後你就可以在你的UITableView使用。

如果asynchrounsly發送您的請求,請不要忘記將數據與

追加 - (無效)連接:(NSURLConnection的*)連接didReceiveData:(NSData的*)數據

相關問題