2014-01-24 2 views
0

버튼과 웹 서비스에 대해 알고 싶습니다. 일반적으로 indexPath.item으로 웹 서비스의 데이터를 보여주기 위해 Uicollectionview을 사용하지만, 사용하지 않으면 Uicollectionview 가능합니까? 웹 서비스에서 데이터를 전달하고 가져올 수 있습니다.웹 서비스 데이터를 버튼으로 확인하는 방법은 무엇입니까?

여기에 어떤 아이디어에 대해 조언을 주시기 바랍니다 코드

-(IBAction)ttButton:(id)sender 
{  
    bookName = @"test"; 
    bookVersion = [[bookList objectAtIndex:indexPath.row]bookVersion];// when I use this it's will crash. 
    _bookPosition = [[bookList objectAtIndex:indexPath.row]bookPosition]; 
    bookId = @"1"; 
    bookPath = @"test001"; 
    pageAmount = 2; 
    mainMenu = @"test"; 

// downloadURL = [[bookList objectAtIndex:indexPath.row]downloadURL]; 
// pageAmount = [[bookList objectAtIndex:indexPath.row]pageAmount]; I want to go like this. but indexPath I can use only in collection view 

     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
      NSString *stringURL = [NSString stringWithFormat:@"http://tlf/testdata/webservice/book_extract.php?main_menu=test&language=en&id=%@",(_bookPosition)]; 
      NSURLResponse *response = nil; 
      NSError *error = nil; 
      NSURL *url = [NSURL URLWithString:stringURL]; 
      NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
      NSURLConnection *urlConnection = [[NSURLConnection alloc]init]; 
      NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; 

      dispatch_async(dispatch_get_main_queue(), ^{ 


       [self connection:urlConnection didReceiveResponse:response]; 
       [self connection:urlConnection didReceiveData:data]; 

       [db saveAssetVersion:_assetVersion]; 


    if([db isDownloaded:bookId bookVersion:[bookVersion floatValue]]){ 

     [self performSegueWithIdentifier:@"test" sender:self]; 


    } 
    else{ 

     [self startDownload]; 
    } 


      }); 
     }); 
} 

입니다. 고맙습니다.

답변

0

데이터를 얻기 위해 코드를 작성한다고 생각해도 Button의 경우에도 호출되고 있습니다. 어쨌든 NSURLConnection 클래스의 델리게이트를 가져 오는 코드가있는 클래스로 설정해야합니다.

기본적으로 UICollectionView 또는 UIButton을 사용하여 전혀 차이가 없습니다. 이는 사용자가 시스템과 상호 작용하는 방식의 차이 일뿐입니다. 다운로드 및 업데이트 할 코드는 별도이어야하며 비슷하게 호출되어야합니다.

+0

흠, 고맙습니다. 저는 Uicollectionview를 설정하는 것이 잘못되었습니다. –