Vikas Singh
Vikas Singh

Reputation: 1791

when is this called : - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

When is cellForRowAtIndexPath called when the cells of a TableViewController are added dynamicall? Is it after ViewDidLoad? We never trigger anything programatically to tell the app that we have done all the initial work we need to do and now you can start adding the cells with the corresponding details, discousure etc...

I am terribly confused and therefore I have no clue about the flow of execution of controls in a TableViewController. Please help me !

Upvotes: 1

Views: 1762

Answers (4)

user23743
user23743

Reputation:

The tableview knows that when it's unarchived it needs to load its data.

As a general tip, if you want to know when a method is executed you can set a breakpoint. Xcode lets you choose whether to pause or continue when a breakpoint is met, so you can trigger a set of actions when different methods are encountered to find out what order thet occur in.

Upvotes: 2

Anshuk Garg
Anshuk Garg

Reputation: 1540

it is called after viewDidLoad, and yes it is called for every cell dynamically. you can put breakpoints and check the flow. hope it helps. happy coding :)

Upvotes: 2

Manuel
Manuel

Reputation: 10303

The delegate calls for the tableView will only be called if the table exists, for the table to exist the view must exist as it is part of the view. The viewDidLoad is called right after creating the view. So in short: viewDidLoad is called BEFORE tableView:cellForRowAtIndexPath:.

Upvotes: 5

Novarg
Novarg

Reputation: 7450

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is a delegate method of a UITableView. It is called every time a cell is becoming visible(appearing on the screen due to scrolling for example).

And at the beginning it is called after viewDidLoad as many times as necessary(depending how many cells should be present).

Hope it helps

Upvotes: 3

Related Questions