【发布时间】: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