【问题标题】:How to Check Web service data with button?如何使用按钮检查 Web 服务数据?
【发布时间】:2014-01-24 07:45:56
【问题描述】:

我需要了解一些关于按钮和网络服务的知识,通常我使用Uicollectionview 来显示来自indexPath.item 的网络服务的数据,但如果我不使用Uicollectionview 这可能吗?从 Web 服务传递和获取数据。

这里是代码

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


            });
        });
}

请对任何想法提出建议。非常感谢。

【问题讨论】:

    标签: ios uibutton uicollectionview ibaction nsindexpath


    【解决方案1】:

    我认为在 Button 的情况下甚至不会调用您获取数据的代码。无论如何,您需要将 NSURLConnection 类的委托设置为获取代码所在的类。

    本质上,使用 UICollectionView 或 UIButton 完全没有区别。这只是用户与系统交互方式的区别。下载和更新的代码应该是分开的,并且应该由两者类似地调用。

    【讨论】:

    • hmm,谢谢我设置Uicollectionview是错误的,这是工作而不是区别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多