Question

I need to know something about button and web service ,normally I'm use Uicollectionview for show data from web service by indexPath.item but if I don't use Uicollectionview It's possible? to pass and get data from web service.

Here's code

-(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];
    }


            });
        });
}

Please Advice for any Idea. Thank you very very much.

Was it helpful?

Solution

I dont think you code to get the data is even being called in the case of Button. Anyway, you need to set the delegate of your NSURLConnection class to the class where fetching code is.

Essentially, there is no difference at all using UICollectionView or UIButton. That is just the difference of how user interacts with the system. The code to download and update should be seperate and should be called by both similarly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top