reordering control in UITableView

前端 未结 5 699
青春惊慌失措
青春惊慌失措 2020-12-29 05:20

I am developing a game in which I am using a UITableView which has custom cell (UItableViewCell subclass).

In editing mode:

相关标签:
5条回答
  • 2020-12-29 05:57

    You should use this method for hiding delete button.

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        return UITableViewCellEditingStyleNone;
    }
    
    0 讨论(0)
  • 2020-12-29 06:02

    Swift 5.0

    If you want to disable all other editing options for your tableView's cells except the one that allows you to reorder them then just implement those methods from UITableViewDelegate:

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    // Removes the ability to delete current cell
    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
        return UITableViewCellEditingStyle.none
    }
    
    func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    0 讨论(0)
  • 2020-12-29 06:06
     tableView.showsReorderControl = YES; // to show reordering control
    

    To dissmiss delete control, in your UITableViewDelegate add

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return UITableViewCellEditingStyleNone;
    }
    
    0 讨论(0)
  • 2020-12-29 06:15

    I know this answer might be late, but I'm putting it just for people who still need it. Just implement the following methods:

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
        return YES;
    }
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        return UITableViewCellEditingStyleNone;
    }
    - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
        return NO;
    }
    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
        return YES;
    }
    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
    
    }
    
    0 讨论(0)
  • 2020-12-29 06:20

    thanks a lot oxigen it worked .... i was writing this in

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
         static NSString *CellIdentifier = @"Cell";
    
         UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
    
         if (!cell) {
             cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
         }
    
         cell.showsReorderControl = YES; // to show reordering control
    
        return cell;
    }
    

    but i dint write the method which you have given

    Thanks a tons

    0 讨论(0)
提交回复
热议问题