[英]Download option on long press of UITableViewCell
I have a UITableView that is populated with an array, it contains cell label and cell detail text, the detail text is basically the URL at which the file is saved. 我有一个用数组填充的UITableView,它包含单元格标签和单元格详细信息文本,详细信息文本基本上是保存文件的URL。 I want that on long press of the uitableviewcell a pop up comes up which has the option to download the file and on clicking that option the file is saved in a specific directory on the phone memory.
我希望在长按uitableviewcell时弹出一个弹出窗口,该弹出窗口可以选择下载文件,然后单击该选项将文件保存在手机内存中的特定目录中。
How can i do that? 我怎样才能做到这一点?
Add gesture to your cell object 向您的单元格对象添加手势
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.0; //seconds
lpgr.delegate = self;
[objMyTableViewCell addGestureRecognizer:lpgr];
[lpgr release];
Handle it 处理它
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
UITableVIewCell *objTableCell = (UITableVIewCell*)gestureRecognizer
NSURL *url = [NSURL URLWithString:objTableCell.lable.text];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request setDownloadDestinationPath:[NSString stringWithFormat:@"%@",filePath]]; //use the path from earlier
[queue addOperation:request]; //queue is an NSOperationQueue
[request setDownloadProgressDelegate:self];
[request setShowAccurateProgress:YES];
}
Response method for download file 下载文件的响应方法
- (void)requestDone:(ASIHTTPRequest *)request
{
NSString *response = [request responseString];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"hurreh!!"
message: @"Your download complete"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
//Do something useful with the content of that request.
}
- (void)requestWentWrong:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
For long press on the UITableViewCell
you can use the UILongPressGestureRecognizer . 长按
UITableViewCell
可以使用UILongPressGestureRecognizer 。 To show the options you can use the UIActionSheet . 要显示选项,可以使用UIActionSheet 。 To download file you can use NSURLConnection or ASIHTTPRequest .
要下载文件,可以使用NSURLConnection或ASIHTTPRequest 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.