做項目中遇到一個小問題,給大家分享一下
以前做刪除是這樣,實現UITableView的代理方法即可
// 設Cell編輯- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{    return YES;}// 定義編輯樣式- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{    return UITableViewCellEditingStyleDelete;}// 進入編輯模式,進行刪除操作- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{    if (editingStyle == UITableViewCellEditingStyleDelete) {        // Delete the row from the data source.      }}// 修改編輯按鈕文字- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{    return @"刪除";}OK 上面可以,但是因為項目支持iOS8.0以上,并且需要左滑刪除和重命名兩種編輯模式,所以我選用了IOS8.0以后的新代理方法
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{        UITableViewRowAction *renameRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"重命名" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {               // 重命名操作    }];    UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {                 // 刪除操作    }];       return @[deleteRoWAction,renameRowAction];}這時候側滑,iOS8真機直接側滑沒有反應,調試顯示沒走新代理方法(iOS9以上真機木有問題)。哎 說好的支持iOS8.0以上呢?
解決辦法:
很簡單就是把舊的代理方法寫上就OK,里面什么也不做
// 進入編輯模式,進行刪除操作- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{    }應該是iOS8.0中 若舊的代理方法沒有實現,然后就調用新的代理方法
新聞熱點
疑難解答