Dude named Ben
Dude named Ben

Reputation: 547

How to display count of rows in NSTableView

I am a cocoa newbie so I apologize if this is a stupid question.

I have a NSTableView that is being populated by a OpenPanel and all works ok.

Now I'd like to show the number of items in the NSTableView in a NSTextField. How do I get the number of items of the NSTableView? Do I use numberOfRowsInTableView?

Also, as a followup, what is the ideal way to catch updates to the NSTableView regardless how they happen, either from File Menu, Toolbar or drap and drop?

Thanks.

Upvotes: 0

Views: 1594

Answers (1)

Trausti Thor
Trausti Thor

Reputation: 3774

Best is just to ask your datasource. Your datasource is usually an array inside a view controller or at least an object that is a delegate to your tableview.

[anArray count];

Gives you an integer. Given that you have hooked up your textfield, this is what you need :

myTextfield.text = [NSString stringWithFormat:@"%i", [anArray count]];

Simple as that.

Upvotes: 1

Related Questions