简体   繁体   English

当用户滑动并查看“删除”按钮时,如何更新UITableView单元格?

[英]How to update UITableView cells when user swipe and see 'Delete' button?

I have UITableVIew table. 我有UITableVIew表。

I implemented deleting in method tableView:commitEditingStyle:forRowAtIndexPath: of UITableViewDataSource Protocol. 我在UITableViewDataSource协议的tableView:commitEditingStyle:forRowAtIndexPath:方法中实现了删除。

All work fine here. 在这里一切正常。 Useful question on subject here Deleting table row with animation using core data . 有关主题的有用问题,请使用核心数据通过动画删除表格行

But every cell shows timer which count down and I have issue with this. 但是每个单元格都显示倒计时的计时器,我对此有疑问。

I use NSTimer in following way: 我通过以下方式使用NSTimer

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

... ...

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

When user swipes to delete timer, button "Delete" disappear when [tableView reloadData]; 当用户滑动删除计时器时, [tableView reloadData];按钮“ Delete”消失[tableView reloadData]; called. 叫。

I want to implement updating timer count down values on table cells which allows user to use swipe with "Delete" smoothly. 我想在表格单元格上实现更新计时器倒计时值,从而允许用户平稳地使用“删除”滑动。

How to achieve this? 如何实现呢?

I was not able to obtain working behaviour with the call: 我无法通过电话获得工作行为:

[tableView reloadData];

The working solution is to update cell components manually and not to call [table reloadData] 可行的解决方案是手动更新单元组件,而不是调用[table reloadData]

Code of updateTickerHandler: could be updated in the following way: 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];
}
 - (void)updateTickerHandler:(NSTimer*)timer
{
 [Table beginUpdates];
 [Table reloadData];
 [Table endUpdates];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM