views:

305

answers:

1

Hello everybody, Today my question is about UITableViewController-s In particular I have noticed that the datasource delegate method

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

is called twice (even if for instance I just create a navigation based application and without adding a line of code.. well adding an NSLog to track it). Now, since in my application I need to determine the number of sections basing the choice on the documents in the file system, I need to call some methods to do so. I have put these methods in the above mentioned method, so they will be called twice, which is something I don't need. The questions are why is it called twice, can I have it called once? I hope that in the official documentation this is not clearly stated (which would mean that I didn't read it at all :) ). By the way I could see others posting similar questions, but I couldn't find a fully satisfying answer. Thank you.

A: 

only - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; method is called twice or all delegate method of uitableview are called twice?

If all are called twice that means ur table is reloading twice...

Are calling the "reload" method of uitableview?

Reena
Hello Reena, thank yo for your attention. Only - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; is called twice. All the other datasource delegate methods are called as many times as you would expect. For instance - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {is called n = (number of visible cells) and it is limited to (number of sections x number of rows per section), each time you scroll and get some new cell visible, it's called. Th only apparently inexplicable double call is for number of sections method...
Can u post the code for numberOfSectionsInTableView method?
Reena
Well...of course, but I can tell you there are just to staments: an NSLog statement and 'return 3;' (no matter the number, same behavior). In the meanwhile I discovered that the issue is there only with UITableViewController, when using just UITableView the method gets called just once as expected.