2

I am using a custom uitableviewcell, which is written in Objective C (everything else I have is written in Swift) for the purpose of having easy customer slide buttons. I have a tableview which uses these cells, and I want it to update even when one of the slide buttons (think slide to delete button) is showing. This is my code here:

dispatch_async(dispatch_get_global_queue(priority, 0)) {
                // do some task
                dispatch_sync(dispatch_get_main_queue()) {

                self.tasksTableView.reloadData()

                    self.tasksTableView.cellForRowAtIndexPath(NSIndexPath(forRow: searchForTaskByName(taskSlices[selectedSlice].name), inSection: 0))!.contentView.addSubview(self.view1)

                    (self.tasksTableView.cellForRowAtIndexPath(NSIndexPath(forRow: searchForTaskByName(taskSlices[selectedSlice].name), inSection: 0)) as! SESlideTableViewCell).setSlideState(SESlideTableViewCellSlideState.Left, animated: true)
    })
    })

Now, the subview I am adding is a rectangle that originally covers the cell, but over time shrinks (kind of like a reverse loading bar). The third line is part of the custom code:

    [UIView animateWithDuration: 0.0 delay: 0.0 options:UIViewAnimationOptionCurveLinear  animations:^{
    //code with animation
    CGRect frame = snapshotView.frame;
    frame.origin.x = targetPositionX;
    snapshotView.frame = frame;
    m_slideState = slideState;
    //[m_leftButtonGroupView layoutIfNeeded];
    //[m_rightButtonGroupView layoutIfNeeded];
} completion:^(BOOL finished){
    if (finished) {
        if (animationId != m_slideAnimationId) {
            return;
        }
        m_slideState = slideState;
        if (slideState == SESlideTableViewCellSlideStateCenter) {
            m_preparedSlideStates = SESlideStateOptionNone;
            isMoved1 = NO;
            [self cleanUpSlideView];
        }
    }
}];

This moves the cell to keep the button in view. Now, the problem is, the tableview has to reload to show the changes (update subviews??) and this causes the cell to shift back to starting position, then the cell is shifted back to button displaying position. This causes random flashes of the cell. I have already tried reloadCellsAtIndexPaths, same deal. I have tried to hide and unhide around the animations; using different threads; dispatch_sync and dispatch_async; removing the table from superview, updating, and putting back; UIView.animationsSetEnable(false) blocks; deleteCellsAtIndexPaths and insertCellsAtIndexPaths, NOTHING will work. This is reproducible on my iPhone 5 and simulator.

What I really need is to figure out what reloadData does so I can call only the bit I need, and hopefully not animate anything. All my animations used have time 0.0 and no delay. I am running a small counting up algorithm in the background, which is variable++ once every .01 seconds, if this matters. Thank you for any help you can give me, I have been working on this for two days now (I am fairly new to iOS development and I wanted to do my research before asking questions).

CoderDude
  • 21
  • 6
  • I found this thread but I have no idea how to apply it, can anyone help? http://stackoverflow.com/questions/18418466/how-to-reload-uitableview-without-stopping-cell-selection-animation – CoderDude Aug 19 '15 at 03:49

3 Answers3

0

Well, I figured out a REALLY hacky fix. I created a duplicate UITableView, which I placed under the main one. I set the main one to get removed from superview and then put back with the reloadData call and other updates between these two calls. This would reveal the second tableview for a split second, and then 0.5 seconds after the first update I would update the second tableview to keep it current. This actually works. I can't believe it works and I am flabbergasted that it is necessary. I am still definitely looking for a legitimate solution and so I will not be accepting my answer for a while, in case someone can help me out.

CoderDude
  • 21
  • 6
0

dispatch_sync(dispatch_get_main_queue()) { } is the source of your problem change it to dispatch_async(dispatch_get_main_queue()) { // reload table view } and your good to go

DBoyer
  • 3,062
  • 4
  • 22
  • 32
0
[self.tableView registerNib:[UINib nibWithNibName:@"CellXibName" bundle:nil] forCellReuseIdentifier:CELL_IDENTIFIER];

I have the flash problem.I finally find that the cell are not reuse when table reload. I have some query block when I set each cell, The cell always recreate make it flash.

Bill Xie
  • 105
  • 6