UA-17470720-3

Jump to content


Photo
- - - - -

No corresponding actions for some tableView delegate methods


  • Please log in to reply
5 replies to this topic

#1 cyyLy

cyyLy

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 31 posts
Reputation: 0
Neutral

Posted 12 May 2015 - 04:53 PM

I  am trying to use STV to help with tableView creation/management, but also want to do some of the work manually. However, there don't appear to be actions for some of the tableView delegate methods in my particular use-case. My use-case is not to use SCArrayOfItemsSection and the items are not bound, as I want to do it manually.

 

For example, I can't find actions for:

 

tableView:canMoveRowAtIndexPath:

tableView:moveRowAtIndexPath:toIndexPath:

tableView:commitEditingStyle:forRowAtIndexPath:

 

I know for commitEditingStyle, I could use sectionActions.willDeleteItem, but that is only available when using SCArrayOfItemsSection, which I am not.

 

What should I do in this case ?



#2 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 12 May 2015 - 08:37 PM

A) tableView:canMoveRowAtIndexPath:

B) tableView:moveRowAtIndexPath:toIndexPath:

C) tableView:commitEditingStyle:forRowAtIndexPath:

 

A)

The movable state of the cell. Default: FALSE.

@property (nonatomic, readwrite) BOOL movable

 

B)

// Objective-C

modelActions.didMoveCell = ^(SCTableViewModel *tableModel, SCTableViewCell *cell, NSIndexPath *fromIndexPath, NSIndexPath *toIndexPath)

{

    NSLog(@"A cell has been moved from:%@ to:%@.", fromIndexPath, toIndexPath);

};

 

// Swift

modelActions.didMoveCell =

{

    (tableModel, cell, fromIndexPath, toIndexPath) in

 

    NSLog("A cell has been moved from:%@ to:%@.", fromIndexPath, toIndexPath)

}

 

C)

- (void)commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forCellAtIndexPath:(NSIndexPath *)indexPath {

}


  • Tarek and cyyLy like this

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


#3 cyyLy

cyyLy

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 31 posts
Reputation: 0
Neutral

Posted 13 May 2015 - 06:11 AM

Thanks for helping ozie!

 

Didn't see the movable property and I was mistakenly asked about moveRowAtIndexPath when I actually want to know about tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: .

 

- Re. (A), suppose I want all cells in a section/table to be movable. Is there a better way in STV than having to set the movable property on all cells ? The tableView delegate canMoveRowAtIndexPath allows me to consolidate all the decision making into a single method, where I can easily allow/deny movement of entire sections. With movable property, I have to remember to set this property to TRUE each time I add a cell, and also be aware of which section I'm adding it to (ie. asking myself "Does this section allow re-ordering?").

 

- B) per my mixup with the method, how can I achieve the same functionality to tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: in STV ?

 

- C) so for commitEditingStyle, I just use the standard UITableView delegate method ? Is there a reason why there is not an STV action for this, or has it just not been requested before ?



#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 13 May 2015 - 11:29 AM

Hi cyyLy,

 

To answer your questions:

 

A. Yes, the best way to implement that is to simply use an SCArrayOfObjectsSection and have it automatically handle all cell movement/addition/deletion.

 

B. What exactly are you trying to achieve here?

 

C. The reason is that STV automatically handles all this plumbing on your behalf. A commitEditingStyle usually results in either these two cases:

      1. An item being deleted, in which case you would implement the sectionActions.didDeleteItem action.

      2. An item being added, in which case you would implement the sectionActions.didInsertItem action.

 

Again, I am guessing that what you to achieve in B. & C. can be automatically handled by an SCArrayOfObjectsSection. It's very typical that STV users never touch any of these methods directly when they use that.



#5 cyyLy

cyyLy

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 31 posts
Reputation: 0
Neutral

Posted 13 May 2015 - 02:26 PM

Thanks for the answers Tarek.

 

A. I'm trying to convert an app to use STV, but want to handle a lot of the array functionality myself, hence not wanting to use SCArrayOfObjectsSection. Can I still use the UITableView delegate canMoveRowAtIndexPath, without messing up STV functionality ?  I suppose an action method modelActions.willMoveCell could achieve what I'm after without the need to use a delegate.

 

B. To disable moving cell to certain locations, and also fix it to top/botom most row when it's moved to a different section above/below.

 

I suppose my requirement come from me using STV in a partial way, instead of just letting it handle everything. When looking through the STV API docs, I was hoping to come across some actions like "will...Item/Cell" (where ... could be delete/insert/delete), to give me the functionality that the tableview delegate methods give.



#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 May 2015 - 07:37 AM

Hi cyyLy,

 

If you would like to override STV's functionality, then you could simply subclass SCTableViewModel and implement whichever UITableViewDelegate or UITableViewDataSource methods you wish (SCTableViewModel acts as both the delegate and data source for your UITableView). The code should be fairly straightforward, something along these lines:

 

// MasterViewController.m

@interface MyTableViewModel : SCTableViewModel
@end

@implementation MyTableViewModel

// override superclass method
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
    // your custom code here
}

@end



@implementation MasterViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    MyTableViewModel *myTableViewModel = [[MyTableViewModel alloc] initWithTableView:self.tableView];
    // Add any sections here normally
    SCTableViewSection *mySection = [SCTableViewSection sectionWithHeaderTitle:@"My Section"];
    [myTableViewModel addSection:mySection];
    
    // Override STV's default model
    self.tableViewModel = myTableViewModel;
}

@end

 

Hope this helps.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users