Clear table using a button in objective-c

Terry

I'm trying to clear all from a table using a button. Basically reset the table. I use the following to remove one slice at a time but how do I clear all from the table? Thank you in advance!

- (IBAction)handleRemoveSliceTapped:(NSButton *)sender {
NSInteger selectedRow = [self.sliceTable selectedRow];
if (selectedRow < 0) {
    return;
}
if ([self.sliceTimes count] == 0)  {
    return;
}

NSIndexSet *removalSet = [NSIndexSet indexSetWithIndex:selectedRow];
[self.sliceTable removeRowsAtIndexes:removalSet withAnimation:NSTableViewAnimationSlideUp];
[self.sliceTimes removeObjectAtIndex:selectedRow];
[self.sliceTable reloadData];
battlmonstr

If your NSTableViewDataSource numberOfRowsInTableView returns 0, the table will become empty.

Therefore, you can just clear your view model, and reload the table:

[self.sliceTimes removeAllObjects];
[self.sliceTable reloadData];

This is without animation. If you need the animation, include all row indexes in your NSIndexSet, and do the updates between beginUpdates/endUpdates (see https://developer.apple.com/documentation/appkit/nstableview/1527288-beginupdates?language=objc ):

NSIndexSet *removalSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.sliceTimes.count)];
[self.sliceTable beginUpdates];
[self.sliceTable removeRowsAtIndexes:removalSet withAnimation:NSTableViewAnimationSlideUp];
[self.sliceTimes removeAllObjects];
[self.sliceTable endUpdates];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Detect Home Button on Objective-C Framework

Clear table using jQuery

objective-c clear NSURLCredential - NSURLCredentialPersistenceForSession

I want to set pagination using PREV and NEXT button using Objective C?

Objective C MFMailComposeViewController Cancel -> Cancel button not working

How Can I Clear Selection of NSComboBox in Swift or Objective-C?

Place a button on Custom view in Objective C

Change image when a button is clicked using Objective-C

Objective C, using an if statement with a button's text

How to clear effect of a click button using jquery

iOS, objective C, referencing a button by tag

Objective C number keypad, custom comma button

Objective C How to animate Subview with click in Button

Objective C: Back button segue not working

Objective C trying to add border to button

button in webView execute Objective C method

Dynamically add rows to table in sqlite (using objective c)

Objective-c clear cache NSCachedURLResponse

Android clear view using button

Set background image of Button in Objective-C

how to highlight multiple rows in a table view using objective-C

Using the multi query function to modify table after clear button is clicked

Clear all Bitmap drawings using push button

Radio Button issue in Objective c

perform a calculation once in Button Action in Objective c

Button to clear Treeview table in Tkinter not working?

Clear input with is binded to event using button

Clear inputs in a div using button + JavaScript

Using A Clear-Filed Button To Clear Some Fields In A Form, But Not All