Search code examples
objective-cnsmutablearraynstableviewnsarraycontroller

Suggestions need for UI : Listing NSMutableArray elements


I am new to Mac app development. So, I am doing some exercises in Objective-C.

I have a nsmutablearray which contains list of names. I want to display a name list using MVC approach and I want perform some action while pressing name in the list view.

I came across some example and googling most of them choose NSTableView and every example has with add and remove button. I am also chose same approach which has a window controller, array controller and xib file. My xib file contains nstableview and nstablecolumn. How can I add the nsmutablearray to nstableview without using add button action event binding ?

-( void ) addName : ( NSString* ) name
{
    [ list addObject : [ [ Name alloc ] initWith : name ] ] 
    [ nameListTable reloadData ] ;
}

Solution

  • You cannot add nsmutablearray to xib. You need a Array controller Interface object which can be added in xib. Then you need to bind array controller's content array with the array created in viewController/windowController class. Then you need to bind the table view content with ArrayController's content.

    https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html