Answer the question
In order to leave comments, you need to log in
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];
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question