Objective c 如何使用进程指示器单元格OSX制作类似torrent的可下载文件表?目标-C
我正在构建一个用于从服务器下载文件的应用程序,我有一个带有自定义单元格的Objective c 如何使用进程指示器单元格OSX制作类似torrent的可下载文件表?目标-C,objective-c,macos,Objective C,Macos,我正在构建一个用于从服务器下载文件的应用程序,我有一个带有自定义单元格的NSTableViewController,其中包含进度指示器,但我在为每行/可下载文件绘制单元格时遇到了问题。当我开始下载时,进度单元格似乎只是第一个创建的单元格的副本,进度更新有点模糊,当我选择多行下载时,它在最后选择的行上只显示一个进度。如果有人能告诉我哪里做错了 以下是在-(NSView*)tableView:(NSTableView*)tableView viewForTableColumn:(NSTableCol
NSTableViewController
,其中包含进度指示器,但我在为每行/可下载文件绘制单元格时遇到了问题。当我开始下载时,进度单元格似乎只是第一个创建的单元格的副本,进度更新有点模糊,当我选择多行下载时,它在最后选择的行上只显示一个进度。如果有人能告诉我哪里做错了
以下是在-(NSView*)tableView:(NSTableView*)tableView viewForTableColumn:(NSTableColumn*)tableColumn行:(NSInteger)行中绘制单元格的代码方法:
if([identifier isEqualToString:@"status"]) {
if ([selectedIndexes count] >0) {
for (indexNumber in selectedIndexes) {
ProgressBarCell *statusCell = [tableView makeViewWithIdentifier:@"StatusCell" owner:self];
progressCellArray = [self populateArrayOfProgressBarCells:selectedIndexes with:statusCell];
if ([indexNumber integerValue] == row) {
if (downloadTask != nil) {
[statusCell.imageView
setImage:[NSImage imageNamed:@"downloading"]];
[statusCell.textField setStringValue:@"downloading"];
for (int i = 0; i < statusCell.progressBar.maxValue; i++) {
[statusCell.progressBar setDoubleValue:[self getProgressPercentageForRowIndex:[indexNumber integerValue]]];
[statusCell.progressBar displayIfNeeded];
[statusCell.progressBar setUsesThreadedAnimation:YES];
[statusCell.progressBar
startAnimation:statusCell.progressBar];
}
if (statusCell.progressBar.doubleValue == statusCell.progressBar.maxValue) {
[statusCell.textField setStringValue:@"downloaded"];
[statusCell.imageView setImage:[NSImage imageNamed:@"finishedDownload"]];
}
return statusCell;
}
return notSelectedStatusCell = statusCell;
}
}
}
return notSelectedStatusCell;
}
if([标识符IsequalString:@“状态”]){
如果([selectedIndexes count]>0){
for(选定索引中的索引编号){
ProgressBarCell*statusCell=[tableView makeViewWithIdentifier:@“statusCell”所有者:self];
ProgressCellray=[自填充ArrayOfProgressBarcells:SelectedIndex with:statusCell];
if([indexNumber integerValue]==行){
如果(下载任务!=nil){
[statusCell.imageView
setImage:[NSImage ImageName:@“正在下载”];
[statusCell.textField setStringValue:@“下载”];
对于(int i=0;i
表格视图:viewForTableColumn:行:
不绘制NSTableView
通过调用tableView:viewForTableColumn:row:
向代理请求单元格视图。单元视图作为表视图的子视图添加。不可见的单元视图被重用。不能为多行返回同一单元格视图tableView:viewForTableColumn:row:
应返回该行的单元格视图,而不执行其他操作。将设置单元视图的子视图的值。例如:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
DownloadItem *item = self.data[row];
if ([tableColumn.identifier isEqualToString:@"status"]) {
StatusCellView *statusCell = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
statusCell.progressIndicator.doubleValue = item.progress;
if (item.finished) {
statusCell.textField.stringValue = @"downloaded";
statusCell.imageView.image = [NSImage imageNamed:NSImageNameMenuOnStateTemplate];
}
else
if (item.downloading) {
statusCell.textField.stringValue = @"downloading";
statusCell.imageView.image = [NSImage imageNamed:NSImageNameMenuMixedStateTemplate];
}
else {
statusCell.textField.stringValue = @"paused";
statusCell.imageView.image = nil;
}
return statusCell;
}
else {
NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
cellView.textField.stringValue = item.title;
return cellView;
}
return nil;
}
NSInteger row = [self.data indexOfObjectIdenticalTo:item];
NSInteger column = [self.tableView columnWithIdentifier:@"status"];
[self.tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:column]];
当值更改且单元视图应更新时,重新加载单元。例如:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
DownloadItem *item = self.data[row];
if ([tableColumn.identifier isEqualToString:@"status"]) {
StatusCellView *statusCell = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
statusCell.progressIndicator.doubleValue = item.progress;
if (item.finished) {
statusCell.textField.stringValue = @"downloaded";
statusCell.imageView.image = [NSImage imageNamed:NSImageNameMenuOnStateTemplate];
}
else
if (item.downloading) {
statusCell.textField.stringValue = @"downloading";
statusCell.imageView.image = [NSImage imageNamed:NSImageNameMenuMixedStateTemplate];
}
else {
statusCell.textField.stringValue = @"paused";
statusCell.imageView.image = nil;
}
return statusCell;
}
else {
NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
cellView.textField.stringValue = item.title;
return cellView;
}
return nil;
}
NSInteger row = [self.data indexOfObjectIdenticalTo:item];
NSInteger column = [self.tableView columnWithIdentifier:@"status"];
[self.tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:column]];
tableView:viewfortable列:行:
不绘制NSTableView
通过调用tableView:viewForTableColumn:row:
向代理请求单元格视图。单元视图作为表视图的子视图添加。不可见的单元视图被重用。不能为多行返回同一单元格视图tableView:viewForTableColumn:row:
应返回该行的单元格视图,而不执行其他操作。将设置单元视图的子视图的值。例如:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
DownloadItem *item = self.data[row];
if ([tableColumn.identifier isEqualToString:@"status"]) {
StatusCellView *statusCell = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
statusCell.progressIndicator.doubleValue = item.progress;
if (item.finished) {
statusCell.textField.stringValue = @"downloaded";
statusCell.imageView.image = [NSImage imageNamed:NSImageNameMenuOnStateTemplate];
}
else
if (item.downloading) {
statusCell.textField.stringValue = @"downloading";
statusCell.imageView.image = [NSImage imageNamed:NSImageNameMenuMixedStateTemplate];
}
else {
statusCell.textField.stringValue = @"paused";
statusCell.imageView.image = nil;
}
return statusCell;
}
else {
NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
cellView.textField.stringValue = item.title;
return cellView;
}
return nil;
}
NSInteger row = [self.data indexOfObjectIdenticalTo:item];
NSInteger column = [self.tableView columnWithIdentifier:@"status"];
[self.tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:column]];
当值更改且单元视图应更新时,重新加载单元。例如:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
DownloadItem *item = self.data[row];
if ([tableColumn.identifier isEqualToString:@"status"]) {
StatusCellView *statusCell = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
statusCell.progressIndicator.doubleValue = item.progress;
if (item.finished) {
statusCell.textField.stringValue = @"downloaded";
statusCell.imageView.image = [NSImage imageNamed:NSImageNameMenuOnStateTemplate];
}
else
if (item.downloading) {
statusCell.textField.stringValue = @"downloading";
statusCell.imageView.image = [NSImage imageNamed:NSImageNameMenuMixedStateTemplate];
}
else {
statusCell.textField.stringValue = @"paused";
statusCell.imageView.image = nil;
}
return statusCell;
}
else {
NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
cellView.textField.stringValue = item.title;
return cellView;
}
return nil;
}
NSInteger row = [self.data indexOfObjectIdenticalTo:item];
NSInteger column = [self.tableView columnWithIdentifier:@"status"];
[self.tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:column]];
tableView:viewfortable列:行:
不绘制NSTableView
通过调用tableView:viewForTableColumn:row:
向代理请求单元格视图。单元视图作为表视图的子视图添加。不可见的单元视图被重用。更新进度指示器(表视图:ViewForTable列:行:)您可以通过查看列:行:makeifneedly:获得单元格视图。感谢您的回答,但这并不能解决我的问题。我将尝试对问题进行短屏幕录制。以下是有关问题的视频表视图:viewfortable列:行:
不绘制NSTableView
通过调用tableView:viewForTableColumn:row:
向代理请求单元格视图。单元视图作为表视图的子视图添加。不可见的单元视图被重用。要更新进度指示器(在tableView:viewForTableColumn:row:
),您可以使用viewAtColumn:row:makeifneedly:
)获取单元格视图。感谢您的回答,但这并不能解决我的问题。我将尝试对该问题进行短屏幕录制。以下是有关该问题的视频