Search code examples
objective-cxcodenstableviewnsarraycontroller

How to clear a NSTableView's data source


I am trying to make a method in which the data source for my NATableView is cleared, but I cannot figure out how to do this anywhere.

Here is the code I am using to send an array called final to my table view.

// I want to clear it here before filling it again.  
for (int i = 0; i < [final count]; i++) {
    [myArrayController addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:final[i], @"File Name", nil]];
}

Any help would be great!


Solution

  • If you are using an NSMutableArray and myArrayController is your mutable array you want to call

    [myArrayController removeAllObjects]; 
    

    before you enter the for-loop.