Iphone 基于单元格索引在tableview单元格中放置进度视图
我是iphone新手。我有一个小问题,我有一个CustomCell类,我声明了所有我需要的元素,如下所示Iphone 基于单元格索引在tableview单元格中放置进度视图,iphone,Iphone,我是iphone新手。我有一个小问题,我有一个CustomCell类,我声明了所有我需要的元素,如下所示 // CustomCell.h 在这个类中,我将getter和setter方法设置为TitleLabel、PercentageLabel、ProgressView和downloadButton // CustomCell.m 在这个类中,首先将框架设置为,并将图像设置为下载按钮 我的输出屏幕的屏幕截图是 //在我的表视图中,当我们单击下面的方法时,我有一个下载按钮 -(void)dow
// 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;
}
-(UITableViewCell*)tableView:(UITableView*)\u tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
CustomCell*cell=[\u tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil)
{
cell=[[CustomCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier];
}
NSLog(@“indexpath.row为%d”,indexpath.row);
NSLog(@“downloadmanager为%d”,[[[downloadmanager sharedDownloadManager]getDownloads]计数]);
/*如果(indexPath.row,为什么不从头开始在单元格中添加进度视图?
最初将其隐藏,当您触摸下载按钮时,您会告诉手机显示它
我看到您将单元格的indexPath.row存储在下载按钮标记中,您可以使用它来查找所选择的单元格,如下所示
NSIndexPath *cellIndexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:nowIndex];
[cell showProgressBar];
我写了我的头上的代码…没有测试它