2014-09-02 67 views
0

我有Json url.i知道獲取JSON url.but的數據但現在我有一個問題。如何將NSString值傳遞給connectionDidFinishLoading

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"index number %d", indexPath.row); 
    passingDealDec=[titleDecarray objectAtIndex:indexPath.row]; 
    NSLog(@"passingDealDec%@",passingDealDec); 
    // you can see selected row number in your console; 
} 

我需要passingDealDec(的NSString)傳遞給connectionDidFinishLoading方法我想這樣的,但它不是工作

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
if ([getDealsDec isEqualToString:passingDealDec]){ 
      NSLog(@"firstpassingDealDec%@",passingDealDec); 
      NSString *geting2 =[diction valueForKey:@"dealimage"]; 
      NSData *getdata2=[[NSData alloc]initWithData:[NSData dataFromBase64String:geting2]]; 
      NSLog(@"good day2 %@",getdata2); 
      UIImage *singleimage=[UIImage imageWithData:getdata2]; 

      NSLog(@"GetingSingleImage%@",singleimage); 

      //[imagesarray addObject:singleimage]; 

      NSString *Dealtitles =[dealPosted valueForKey:@"deaTitle"]; 
      NSLog(@"Singletitles^^^%@",Dealtitles); 

      NSString *DealPrice=[dealPosted valueForKey:@"price"]; 
      NSLog(@"DealPrice^^^DealPrice%@",DealPrice); 
     } 
} 

請告訴我什麼錯在我code.First告訴我didSelectRowAtIndexPath方法方法調用connectionDidFinishLoading後這可能與否。

感謝高級。

+0

從哪裏調用網址? – BHASKAR 2014-09-02 06:09:28

+0

@BHASKAR我調用viewDidLoad中 – 2014-09-02 06:13:37

+0

的網址,所以當你輕點實現代碼如下passingDealDec爲零 – BHASKAR 2014-09-02 06:17:18

回答

0

如果你知道ConnectionDidFinishLoading是didSelectAtIndexPath 後燒製然後聲明DealDec作爲一個全球性的(比如)變量,所以變量設置爲在didSelectAtIndexPath值,該值將保持原樣設置,您可以在訪問Later函數。

-(void)viewDidLoad{ 
NSString *DealDec; 
} 

P.S-如果你不知道哪種方法是發射前,將兩個斷點,在每一個方法,運行應用程序,看哪個最先被執行。

希望這有助於

[編輯]

didSelectIndexPath{ 
NSURLConnection *myURL; 
Cell.myLabel.text = myURL; //taking that some label text in the cell class has a URl and u want to fire it when u click on it. 
[self.connectionDidFinishLoading:myURL]; 
} 

這樣就解決了問題

+0

謝謝回覆首先調用ConnectionDidFinishLoading,然後當我按的UITableViewCell來電DidselectAtIndexPath但現在我需要後didselectIndexpath我的字符串值傳遞給ConnectionDidFinishLoading請幫助我有可能或沒有。如果可能請幫助 – 2014-09-02 06:12:17

+0

是ConnectionDidFinishLoading自定義方法? – 2014-09-02 06:13:49

+0

否 - (無效)connectionDidFinishLoading:(NSURLConnection的*)連接 { – 2014-09-02 06:14:27

0

你可以在很多的方式做到這一點。

1.You調用此WebService從

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
  1. 您保存在

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

這檢查可以在tableView中完成:didSelectRowAtIndexPath

if ([getDealsDec isEqualToString:passingDealDec]){ 
} 
+0

感謝回覆我會嘗試 – 2014-09-02 06:26:15

+0

如果它的工作,那麼你會接受這個答案,並upvote它 – BHASKAR 2014-09-02 06:29:17

+0

我放置[self viewDidload];在didSelectRowAtIndexPath所以總頁面回憶我不喜歡它所以請幫助我任何其他方式調用 – 2014-09-02 07:12:05