0

我有UITableVIew桌子。

tableView:commitEditingStyle:forRowAtIndexPath:我在协议的方法中实现了删除UITableViewDataSource

在这里一切正常。此处关于主题的有用问题使用核心数据删除带有动画的表格行

但是每个单元格都显示倒计时的计时器,我对此有疑问。

NSTimer以以下方式使用:

timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self
    selector:@selector(updateTickerHandler:) userInfo:nil repeats:YES];

...

- (void)updateTickerHandler:(NSTimer*)timer
{
    [tableView reloadData];
}

当用户滑动删除计时器时,“删除”按钮在[tableView reloadData];调用时消失。

我想在表格单元格上实现更新计时器倒计时值,允许用户顺利使用“删除”滑动。

如何做到这一点?

4

2 回答 2

3

我无法通过调用获得工作行为:

[tableView reloadData];

工作解决方案是手动更新单元组件而不是调用[table reloadData]

updateTickerHandler:可以通过以下方式更新代码:

- (void)updateTickerHandler:(NSTimer*)timer
{
    [tableView beginUpdates];


    // select visible cells only which we will update 
    NSArray *visibleIndices = [tableView indexPathsForVisibleRows];

    // iterate through visible cells
    for (NSIndexPath *visibleIndex in visibleIndices)
    {
        MyTableCell *cell = (MyTableCell*)
            [tableView cellForRowAtIndexPath:visibleIndex];

        // add here code to fill `cell` with actual values
        // visibleIndex can be used to retrieve corresponding data

        ...
    }

    [tableView endUpdates];
}
于 2013-05-26T18:44:13.937 回答
0
 - (void)updateTickerHandler:(NSTimer*)timer
{
 [Table beginUpdates];
 [Table reloadData];
 [Table endUpdates];
}
于 2013-05-08T09:51:41.440 回答