我是iphone的新手。我有一个小问题,我有一个类CustomCell,我已经声明了我需要的所有元素,如下所示
// CustomCell.h
这个类在这里我将getter和setter方法设置为TitleLabel,PercentageLabel,ProgressView,downloadButton
// CustomCell.m
此类在此类中将帧设置为最重要,并将图像设置为下载按钮
我的输出屏幕的屏幕截图是
//在我的表格视图中,当我们点击以下方法执行时,我有一个下载按钮
-(void)downloadButtonClicked:(id)sender
{
NSLog(@"download button clicked");
int index = [sender tag];
NSLog(@"index of the cell is %d",index);
UIButton *button = (UIButton*)sender;
UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
NSLog(@"label text =%@",titleLabel.text);
UIView *senderButton = (UIView*) sender;
NSIndexPath *indexPath = [tableView indexPathForCell: (UITableViewCell*)[[senderButton superview]superview]];
NSLog(@"indexpath is %d",indexPath.row);
CustomCell *customCell = [[CustomCell alloc]init];
progressView = [[UIProgressView alloc]init];
// [customCell.contentView insertSubview:progressView atIndex:indexPath.row];
[customCell.contentView addSubview:progressView];
selectedBookTitle = titleLabel.text;
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSMutableArray *allDownloadLinks;
biblePlayerViewController = [[BiblePlayerViewController alloc]init];
allDownloadLinks = [biblePlayerViewController allDownloadLinks];
NSLog(@"all Download Links are %@",allDownloadLinks);
biblePlayerViewController.indexOfSelectedBookTitle = [[appDelegate getBookNames]indexOfObject:selectedBookTitle];
Download* download = [Download downloadWithTitle:selectedBookTitle url:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.audiotreasure.com/%@.zip",[allDownloadLinks objectAtIndex:(biblePlayerViewController.indexOfSelectedBookTitle)]]]PathtoSave:documentsPath];
[[DownloadManager sharedDownloadManager] queueDownload: download];
}
//在cellForRowAtIndexPath tableview委托方法中,我编写了这样的代码
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSLog(@"indexpath.row is %d",indexPath.row);
NSLog(@"downloadmanager is %d",[[[DownloadManager sharedDownloadManager]getDownloads]count]);
/* if (indexPath.row<[[[DownloadManager sharedDownloadManager] getDownloads]count])
{
cell.TitleLabel.text = ((Download*)[[[DownloadManager sharedDownloadManager] getDownloads] objectAtIndex:indexPath.row]).title_;
cell.ProgressView.progress = (float)(((Download*)[[[DownloadManager sharedDownloadManager] getDownloads] objectAtIndex:indexPath.row]).PercentageDownloaded_ )/100.0f;
cell.PercentageLabel.text = [NSString stringWithFormat:@"%d %%",((Download*)[[[DownloadManager sharedDownloadManager] getDownloads] objectAtIndex:indexPath.row]).PercentageDownloaded_];
}
else
{
[tableView reloadData];
}*/
NSString *titleLabel = [[appDelegate getBookNames]objectAtIndex:indexPath.row];
cell.TitleLabel.text = titleLabel;
cell.downloadButton.tag = indexPath.row;
NSLog(@"tag is %d",cell.downloadButton.tag);
[cell.downloadButton addTarget:self action:@selector(downloadButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
我的问题是我在屏幕截图中有66个单元格,我们有一个名为Revelation的书名。我的tableview中有第66个单元格(索引是65)。当我点击该单元格中的下载按钮时,我必须仅显示该特定单元格中的进度视图(第65个单元格)。我每1秒重新加载一次表视图,因为在放置进度视图后,我们必须在该单元格中显示该进度视图中的进度。所以,我们如何放置该特定单元格索引中的进度视图。
答案 0 :(得分:1)
为什么不从头开始在单元格中添加进度视图? 最初隐藏它,当你触摸下载按钮时,你告诉单元格显示它。
我看到您将单元格的indexPath.row存储在下载按钮标记中。您可以使用它来找出下面选择的单元格。
NSIndexPath *cellIndexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:nowIndex];
[cell showProgressBar];
我写了我的头顶代码..没有测试过它。