【问题标题】:UITableView with cell containing progress bar带有包含进度条的单元格的 UITableView
【发布时间】:2013-03-24 17:22:34
【问题描述】:

我有一个表格视图,其中包含 2 种类型的单元格,一个是普通字幕类型的单元格,一个是包含一个 progressView 的自定义单元格。当委托调用完成百分比方法时,该单元格(表格视图中只有一个单元格可以有进度条)需要更新进度视图。

代码如下:

- (void)finishedPercent
{
    percent += 0.01;

    // reload cell
    //NSLog(@"received percent");
    [self.tableView beginUpdates];
    [self.tableView reloadRowsAtIndexPaths:@[indexPathOfRunningFormula] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];
}

它会非常频繁地更新,从接近零到 90% 或类似的东西。

这是输出的一部分

2013-03-24 19:15:53.285 FutureSight[5455:12e07] *** Assertion failure in -[_UITableViewUpdateSupport _setupAnimationsForNewlyInsertedCells], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableViewSupport.m:1145
2013-03-24 19:16:03.850 FutureSight[5455:16003] percent done
2013-03-24 19:16:04.325 FutureSight[5455:16103] percent done
2013-03-24 19:16:04.372 FutureSight[5455:16103] percent done
2013-03-24 19:16:04.478 FutureSight[5455:16003] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:909
2013-03-24 19:16:04.477 FutureSight[5455:12e07] percent done
2013-03-24 19:16:07.727 FutureSight[5455:16103] percent done
2013-03-24 19:16:07.790 FutureSight[5455:16103] percent done
2013-03-24 19:16:07.801 FutureSight[5455:16003] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:909

有什么问题?

将代码更改为

- (void)finishedPercent
{
    percent += 0.01;
    PSFormulaProgressCell *cell = (PSFormulaProgressCell *)[self.tableView cellForRowAtIndexPath:indexPathOfRunningFormula];
    cell.progress.progress = percent;

//    // reload cell
    NSLog(@"received percent");
//    [self.tableView beginUpdates];
//    [self.tableView reloadRowsAtIndexPaths:@[indexPathOfRunningFormula] withRowAnimation:UITableViewRowAnimationNone];
//    [self.tableView endUpdates];
}

还是不行,它会显示进度条,但更新会填充它..

FutureSight(6368,0xb0115000) malloc: *** error for object 0xff39fd0: double free
*** set a breakpoint in malloc_error_break to debug
FutureSight(6368,0xb0365000) malloc: *** error for object 0xff392c0: double free
*** set a breakpoint in malloc_error_break to debug
2013-03-24 20:27:13.188 FutureSight[6368:12e03] received percent
2013-03-24 20:27:13.189 FutureSight[6368:15503] received percent
2013-03-24 20:27:13.252 FutureSight[6368:15503] received percent
2013-03-24 20:27:13.321 FutureSight[6368:15407] received percent
2013-03-24 20:27:13.383 FutureSight[6368:12e03] received percent
2013-03-24 20:27:13.444 FutureSight[6368:15407] received percent
2013-03-24 20:27:13.444 FutureSight[6368:12e03] received percent
2013-03-24 20:27:13.509 FutureSight[6368:12e03] received percent
2013-03-24 20:27:13.509 FutureSight[6368:15407] received percent
2013-03-24 20:27:13.579 FutureSight[6368:15503] received percent
FutureSight(6368,0xb0261000) malloc: *** error for object 0x7a0c400: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
2013-03-24 20:27:13.846 FutureSight[6368:15407] received percent
2013-03-24 20:27:13.846 FutureSight[6368:12603] received percent

【问题讨论】:

  • 为什么要重新加载行?为什么不直接更新进度条呢?另外,请确保在主线程而不是后台线程中调用此 finishedPercent 方法。
  • 显然指示更新进度条也不起作用
  • 你还没有确认finishedPercent是否被主线程调用。
  • 嗯......这似乎是问题......它没有在主线程上调用......它现在可以工作

标签: ios uitableview uiprogressview


【解决方案1】:

您应该只更新 UIProgressView,而不是整个单元格。不需要“reloadRowsAtIndexPaths”。

【讨论】:

  • 更新后有没有试过[cell.progress setNeedsDisplay]?
  • 这很奇怪。你的finishedPercent方法在哪里调用?
  • 它是从一个对象调用的,这个对象是一个委托给......“收到的百分比”意味着正在调用这个函数......但是进度视图没有设置新的百分比...... .
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多