Iphone UIProgressView在滚动tableview时隐藏
在我的iphone应用程序中,我有一个按钮,当我点击该按钮时,下载操作开始,我用Iphone UIProgressView在滚动tableview时隐藏,iphone,multithreading,uitableview,asihttprequest,uiprogressview,Iphone,Multithreading,Uitableview,Asihttprequest,Uiprogressview,在我的iphone应用程序中,我有一个按钮,当我点击该按钮时,下载操作开始,我用UIProgressView替换该按钮。此UIProgressView将显示下载进度。但一旦添加了UIProgressView,当我滚动时它就会消失。这是我的密码: // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIn
UIProgressView
替换该按钮。此UIProgressView
将显示下载进度。但一旦添加了UIProgressView,当我滚动时它就会消失。这是我的密码:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UIMenuItemCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [self getCellContentView:CellIdentifier];
cell.cellitemImage = (UIImageView *)[cell viewWithTag:2];
cell.cellItemButton = (UIButton *)[cell viewWithTag:3];
DataBaseClass *itemObj = [appDelegate.itemArray objectAtIndex:indexPath.row];
NSString *url;
if([itemObj.itemStatus isEqualToString:@"Available"]){
cell.cellItemButton.userInteractionEnabled = YES;
cell.userInteractionEnabled = YES;
[cell.cellItemButton setTitle:@"" forState:UIControlStateNormal];
[cell.cellItemButton setBackgroundImage:[UIImage imageNamed:@"img_normal"] forState:UIControlStateNormal];
[cell.cellItemButton setBackgroundImage:[UIImage imageNamed:@"img_pressed"] forState:UIControlStateHighlighted];
[cell.cellItemButton addTarget:self action:@selector(download) forControlEvents:UIControlEventTouchUpInside];
url = [NSString stringWithFormat:@"%@",itemObj.availableIcon];
}else if([itemObj.itemStatus isEqualToString:@"Downloading"]){
url = [NSString stringWithFormat:@"%@",itemObj.availableIcon];
[cell.contentView addSubview:myprogressView];
cell.cellItemButton.hidden = YES;
}
[cell.cellitemImage setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"item01.png"]];
cell.cellItemName.text = [NSString stringWithFormat:@"%@",itemObj.itemName];
return cell;
}
- (void)download{
UIButton *btn = (UIButton *)clickedBtnSender;
UIMenuItemCell *cell = [(UIMenuItemCell *)[[clickedBtnSender superview] superview] retain];
myprogressView = [[[CustomProgressView alloc]initWithFrame:CGRectMake(25, 140, 100, 21)] retain];
myprogressView.tag = selectedTag;
btn.hidden = YES;
for (UIProgressView *currentProgress in cell.contentView.subviews) {
if ([currentProgress isKindOfClass:[UIProgressView class]]){
[currentProgress removeFromSuperview];
}
}
[cell.contentView addSubview:myprogressView];
}
请帮忙
编辑
- (UIMenuItemCell *) getCellContentView:(NSString *)cellIdentifier {
CGRect CellFrame = CGRectMake(0, 0, 150, 60);
CGRect imgFrame = CGRectMake(20, 48, 110, 123);
CGRect btnFrame = CGRectMake(25, 140, 100, 26);
CGRect progressFrame = CGRectMake(25, 140, 100, 21);
UIImageView *itemImg;
UIButton *itemBtn;
UIProgressView *itemProgView;
UIMenuItemCell *cell = [[UIMenuItemCell alloc] init] ;
cell.frame = CellFrame;
//Initialize ImageView
itemImg = [[UIImageView alloc]initWithFrame:imgFrame];
itemImg.tag = 2;
[cell.contentView addSubview:itemImg];
//Initialize Button
itemBtn = [UIButton buttonWithType:UIButtonTypeCustom];
itemBtn.frame = btnFrame;
itemBtn.tag = 3;
itemBtn.titleLabel.textColor = [UIColor blueColor];
itemBtn.titleLabel.font = [UIFont systemFontOfSize:9.0];
[cell.contentView addSubview:itemBtn];
//Initialize ProgressView
itemProgView = [[CustomProgressView alloc]initWithFrame:progressFrame];
itemProgView.tag = 4;
//[cell.contentView addSubview:itemProgView];
return cell;
}
我认为每个单元格都需要有唯一的cellIdentifier
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d", indexPath.row];
UIMenuItemCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [self getCellContentView:CellIdentifier];
// Some codes here
}
return cell;
}
基于您上次编辑的附加信息
改变
UIMenuItemCell *cell = [[UIMenuItemCell alloc] init];
到
您在哪里分配带有标记2和3的imageview和按钮??这肯定会对你有所帮助。我试过了,但当我开始下载时,它会显示进度视图。但是如果有两个进度视图,当我一次只滚动一个时就会出现。我试过了,现在向下滚动时效果很好,但当我向上滚动时问题仍然存在。您是否检查了此行“if(cell==nil){cell=[self getCellContentView:CellIdentifier];//您的代码在这里}”
UIMenuItemCell *cell = [[UIMenuItemCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier];