Iphone UITableViewCell中的UIProgressbar问题
在我的应用程序中,我有一个tableview。每个单元格包含一个UIButton、一个UIImageView和一个UILabel。单击该按钮时,将使用ASINetworkQueue下载一组文件,此时该按钮将替换为UIProgressView。在下载过程中,如果我滚动表格,应用程序就会崩溃。我在ASIHTTPRequest.m类中得到了错误点Iphone UITableViewCell中的UIProgressbar问题,iphone,uitableview,asihttprequest,Iphone,Uitableview,Asihttprequest,在我的应用程序中,我有一个tableview。每个单元格包含一个UIButton、一个UIImageView和一个UILabel。单击该按钮时,将使用ASINetworkQueue下载一组文件,此时该按钮将替换为UIProgressView。在下载过程中,如果我滚动表格,应用程序就会崩溃。我在ASIHTTPRequest.m类中得到了错误点 + (void)updateProgressIndicator:(id *)indicator withProgress:(unsigned long lo
+ (void)updateProgressIndicator:(id *)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total
{
#if TARGET_OS_IPHONE
// Cocoa Touch: UIProgressView
SEL selector = @selector(setProgress:);
float progressAmount = (float)((progress*1.0)/(total*1.0));
#else
// Cocoa: NSProgressIndicator
double progressAmount = progressAmount = (progress*1.0)/(total*1.0);
SEL selector = @selector(setDoubleValue:);
#endif
if (![*indicator respondsToSelector:selector]) { // here i am getting the error
return;
}
[progressLock lock];
[ASIHTTPRequest performSelector:selector onTarget:indicator withObject:nil amount:&progressAmount callerToRetain:nil];
[progressLock unlock];
}
这是我的代码:
我写了一个UITableViewCell类,比如
@interface UIMenuItemCell : UITableViewCell{
UILabel *cellItemName;
UIImageView *cellitemImage;
UIButton *cellItemButton;
UIProgressView *cellItemProgress;
}
@property (nonatomic, retain) UILabel *cellItemName;
@property (nonatomic, retain) UIImageView *cellitemImage;
@property (nonatomic, retain) UIButton *cellItemButton;
@property (nonatomic, retain) UIProgressView *cellItemProgress;
及
以及下载操作:
- (void)download{
//adding custom method to add the uiprogressview into the selected cell
//and setting the progress delegate for the queue
[self.myQueue setDownloadProgressDelegate:currentProgress];
//then starts download
[self.myQueue go];
}
请分享你的想法。
编辑:在这里,我同时执行多个下载。发生的事情是,当您的手机离开屏幕时,进度条被释放,ASI将尝试更新一个已发布的对象,您需要做的是将两者分开,您可以创建一个downloader类并让该类向cell发送通知,请注意,这需要您做一些工作,祝您好运:)@Omar关于这个问题是正确的。下面是解决方案的示意图: 向DatabaseClass添加类似“downloadProgress”的属性。这可能是一个浮点数,当没有下载发生时,浮点数的值为负值;当下载发生时,浮点数的值介于0.0和1.0之间 将隐藏的进度指示器添加到自定义单元格 按下下载按钮时,获取相应的数据库项目并开始下载(将项目的downloadStatus设置为0.0)。当您从异步进程中获得进展时,更新该项目的下载状态 每次这样做时,让表知道状态已更改(NSNotification可能是一种很好的机制)。表VC应该调用reloadRowsAtIndexPaths:使用一个数组,该数组包含与数据库项对应的索引路径 配置单元格时,表VC应检查项目的下载状态。如果为正值,则取消隐藏状态指示器,并根据浮动设置其进度
另外,关于崩溃:在updateProgress方法中键入指示器(id*)时,似乎至少还有一个问题。这就像一个指向id的指针,几乎肯定不是您想要的。只需使用id,不要将正文中的指示符称为*指示符。这是一个很好的建议,但正如您所说的,它需要做更多的工作。那么,您能提供一些教程或示例代码来实现这一点吗?
- (void)download{
//adding custom method to add the uiprogressview into the selected cell
//and setting the progress delegate for the queue
[self.myQueue setDownloadProgressDelegate:currentProgress];
//then starts download
[self.myQueue go];
}