R
R
Ruslan Shashkov2013-11-15 01:34:29
Objective-C
Ruslan Shashkov, 2013-11-15 01:34:29

OS X Table View: please explain how it works?

Hello! A couple of days ago, for myself (I had free time and I really wanted to try it for a long time) I started to master Objective-C and application development for OS X. I myself have been doing web development for a long time (now mainly NodeJS / JS, before PHP / JS). I more or less figured out the language, I even like it more than JS, somehow everything is logical or something, the code is read very simply. And at first, indeed, as many say, the syntax caused vomiting. Now I'm trying to understand the architecture of applications and I've come across this... The
task is to output data to a table from NSMutableArray. Let's say these are just numeric values, in one column, in general, a primitive task.
I figured out the code, I found a lesson on the internet how to do it. I wrote the data into an array, drew a table, tied the Data source and Delegate to the App Delegate. Launched - everything works, the plate, or rather the column of the plate is filled with values, according to the array.
But the question is, how does it all work? Who calls these methods numberOfRowsInTableView, tableView?

- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView 
    {
    return [self.list count];
}

- (id) tableView: (NSTableView *) tableView objectValueForTableColumn:(NSTableColumn *) tableColumn row: (NSInteger) row 
{
    return [self.list objectAtIndex:row];
}

And what if I have several tables? Why can't I take the array myself and send it to the IBOutlet predefined in my AppDelegate.h for the table, like I do, say when changing the tray menu, or the button text?
Is there any way to programmatically create arrays with NSCell and send them to the right columns of the right tables?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
utercast, 2013-11-15
@rshashkov

It's quite simple, though, and a little confusing at first, as you've already noticed.

MVC, which revolves around the object model, is built on so-called delegates. These are interfaces that help to throw data where necessary and at the same time maintain encapsulation.

In general, the methods you implement are called by the UITableView after rendering. The table first asks its delegate for "DataSource" - "how many cells, in fact, should I draw?". And then - "and what, actually, cells to draw?". Well, etc.

With the help of delegates, some objects can ask other objects to do something for them (delegate). So they are protected from extra paws inside themselves. This is one of the reasons why Objective-C is called "the most ideologically correct OOLE".

I hope I didn't confuse you more ;) Good luck with your studies!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question