UA-17470720-3

Jump to content


Photo
- - - - -

allow delete in edit but disable swipe when not in edit mode


  • Please log in to reply
7 replies to this topic

#1 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 30 December 2014 - 02:06 AM

so i am wanting to disable the swipe to delete function on a cell.. but when the table is in edit mode allow deleting

 

the only way to do this is to 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{
   return self.editing ;
}

 

but there is no action to alter canEditRowAtIndexPath

 

STV is heavy coded for allowDeletingItems  in controlling the UITableViewCellEditingStyleDelete

 

without this cells either allow deleting or not.. and I'm looking at controlling when deleting is available or not

 

or we need a action to be able to set UITableViewCellEditingStyleDelete when we want

 

Oz


Edited by ozie, 30 December 2014 - 02:10 AM.

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 30 December 2014 - 03:07 AM

Hi ozie,

 

Set the cell.editable to YES or NO in the cellActions.willDisplay depending on if [cell.ownerTableViewModel.tableView isEditing] or not.

 

You will probably have to reloadBoundValues/reloadData in the modelActions.shouldBeginEditing and modelActions.shouldEndEditing to get the correct editable  value as the table goes in and out of edit mode.


  • Tarek likes this
Cheers,

Dave

www.dgapps.ie

#3 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 30 December 2014 - 05:25 AM

Hi Dave.. its a start, but i found it buggy  :) plus i never get the should begin or end functions being called.. but thats ok :)

 

if i use 

    section.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        if ([cell.ownerTableViewModel.tableView isEditing] ) {
            cell.editable = YES;
        }
        else {
            cell.editable =  NO;
        }
    };

 

then when the list first loads the rows are not editable.. but if i scroll a little they become editable even thou the cell.editable = YES is NEVER called

 

i think it has to be with willDisplay as opposed to willConfigure


Edited by ozie, 30 December 2014 - 05:27 AM.

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#4 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 30 December 2014 - 09:00 AM

Hi ozie,

 

It looks to work in willConfigure, at least with this code:

 

 

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationBarType = SCNavigationBarTypeEditRight;


    DGObject *object0 = [[DGObject alloc] initWithNameString:@"ZERO"];
    DGObject *object1 = [[DGObject alloc] initWithNameString:@"ONE"];
    DGObject *object2 = [[DGObject alloc] initWithNameString:@"TWO"];

    NSMutableArray *mutableArray = [NSMutableArray arrayWithObjects:
                                    object0,
                                    object1,
                                    object2,
                                    nil];


    SCClassDefinition *classDefinition = [SCClassDefinition definitionWithClass:[DGObject class] propertyNamesString:@"nameString"];
    classDefinition.requireEditingModeToEditPropertyValues = YES;

    SCPropertyDefinition *propertyDefinition = [classDefinition propertyDefinitionWithName:@"nameString"];
    propertyDefinition.type = SCPropertyTypeTextField;
    propertyDefinition.title = @"";

    SCArrayOfObjectsSection *arrayOfObjectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil items:mutableArray itemsDefinition:classDefinition];


    arrayOfObjectsSection.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        NSLog(@"arrayOfObjectsSection cellActions willConfigure:%li",(long)indexPath.row);
        if ([cell.ownerTableViewModel.tableView isEditing]) {
            cell.editable = YES;
        }
        else {
            cell.editable =  NO;
        }
    };

    [self.tableViewModel addSection:arrayOfObjectsSection];


    self.tableViewModel.modelActions.shouldBeginEditing = ^BOOL(SCTableViewModel *tableModel) {
        NSLog(@"self tableViewModel modelActions shouldBeginEditing");
        return YES;
    };

    self.tableViewModel.modelActions.shouldEndEditing = ^BOOL(SCTableViewModel *tableModel) {
        NSLog(@"self tableViewModel modelActions shouldEndEditing");
        return YES;
    };

}

 

And the modelActions get called as well.

 

DGObject is a class with one property,  NSString *nameString.

 

It looks like willConfigure is called twice for every cell, and then twice again on each change of edit mode.


Cheers,

Dave

www.dgapps.ie

#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 30 December 2014 - 01:30 PM

Hi Ozie,

 

You should be actually setting the cell's editing style, but as you discovered earlier it's not as simple as using cellActions.willConfigure, and the cell's owner SCArrayOfObjectsSection also has a say in this depending on its configuration (e.g. allowDeletingItems). The cleanest way to do this is for us to develop a new cellAction in 4.0.6 called 'customEditingStyle'. Once 4.0.6 is out, you should be able to add the following to your code to provide the correct behavior:

 

self.tableViewModel.cellActions.customEditingStyle = ^UITableViewCellEditingStyle(SCTableViewCell *cell, NSIndexPath *indexPath)
{
        // Prevent swipe-to-delete when not in editing mode.
        
        if(cell.ownerTableViewModel.tableView.editing)
            return UITableViewCellEditingStyleDelete;
        //else
        return UITableViewCellEditingStyleNone;
};

 

Hope this helps.



#6 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 30 December 2014 - 03:59 PM

hi Tarek..

can't wait:)

 

Question.. as i have created two tableViewModels tableViewModel1 and tableViewModel2 to control two tables in the view i don't seem to be able to fire off anything like self.tableViewModel1.modelActions.shouldBeginEditing etc

am i missing something??


Edited by ozie, 30 December 2014 - 06:21 PM.

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#7 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 02 January 2015 - 06:55 AM

Have you tried setting the modelActions in a cellAction? Something like this:

 

 arrayOfObjectsSection.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        NSLog(@"arrayOfObjectsSection cellActions willConfigure:%li",(long)indexPath.row);

    cell.ownerTableViewModel.modelActions.shouldBeginEditing = ^BOOL(SCTableViewModel *tableModel) {
        NSLog(@"cell ownerTableViewModel modelActions shouldBeginEditing");
        return YES;
    };

    cell.ownerTableViewModel.modelActions.shouldEndEditing = ^BOOL(SCTableViewModel *tableModel) {
        NSLog(@"cell ownerTableViewModel modelActions shouldEndEditing");
        return YES;
    };

    };



 

 

That might work, although from a brief look at STV source code,  self.tableViewModel1.modelActions.shouldBeginEditing should also work.


  • David DelMonte likes this
Cheers,

Dave

www.dgapps.ie

#8 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 03 January 2015 - 02:20 AM

nop not even that works..

 

seems STV isn't firing off some actions when the tableModel is a build property.. works ok in a test i did when using SCTableViewController with built in tableModels etc


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users