【问题标题】:How to update UITableView cells when user swipe and see 'Delete' button?当用户滑动并看到“删除”按钮时如何更新 UITableView 单元格?
【发布时间】:2013-05-08 09:44:37
【问题描述】:

我有UITableVIew 表。

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

这里一切正常。 关于主题的有用问题在这里Deleting table row with animation using core data

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

我通过以下方式使用NSTimer

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

...

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

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

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

如何做到这一点?

【问题讨论】:

    标签: ios uitableview timer


    【解决方案1】:

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

    [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];
    }
    

    【讨论】:

      【解决方案2】:
       - (void)updateTickerHandler:(NSTimer*)timer
      {
       [Table beginUpdates];
       [Table reloadData];
       [Table endUpdates];
      }
      

      【讨论】:

      • 这并不能解决问题。 “表”是什么意思?
      猜你喜欢
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多