2017-04-17 62 views
0

有時,當執行UITableAction的塊時,整個UITableView會凍結,它不會響應水龍頭或滾動。然而,頁面的其餘部分是響應式的。該行爲看起來像這樣UITableViewAction有時會凍結表

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    __weak ServiceOrderDetailsViewController* weakSelf = self; 

    UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Mark as Complete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
           { 
            if (indexPath.section < weakSelf.sections.count && indexPath.row > 0) 
            { 
             NSString* key = weakSelf.sections[indexPath.section]; 

             if (indexPath.row - 1 < [weakSelf.datasource[key] count]) 
             { 
              //Action 
             } 
            } 

            dispatch_async(dispatch_get_main_queue(),^
            { 
             [weakSelf.UITableView_Bins setEditing:NO animated:YES]; 
             [weakSelf.UITableView_Bins beginUpdates]; 
             [weakSelf.UITableView_Bins reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
             [weakSelf.UITableView_Bins endUpdates]; 
            }); 

           }]; 

button.backgroundColor = [UIColor InTrackGreenColor]; 

return @[button]; 
} 

如果我刪除reloadRows此問題不會發生,但是然後單元格的內容不會更新。

回答

0

所以我們發現了一個解決方法,我想我會分享。這是駭人的,我寧願找到一個更好的方法,但暫時工作。

[self.UITableView_Bins performSelector:@selector(reloadData) withObject:nil afterDelay:0.25 inModes:@[NSDefaultRunLoopMode]]; 

通過延遲一秒鐘,我們避免了凍結問題。