numberOfSectionsInTableView: issue


#1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog(@"Test1");
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    NSLog(@"No. of sections- %d",section);
    return [[[BNRItemStore sharedStore] allItems] count] ;//no. of rows
}

In the above scenario, numberOfSectionsInTableView: method is being called twice. I can’t understand why. The other thing thats confuses me is that when i returned 1 as number of sections in numberOfSectionsInTableView: method, why does it not reflect in - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section method ? It rather logs it as 0.


#2

When you use the statement “NSLog(@“No. of sections- %d”,section);” you are printing out out the number of the current section of the table view, which in your case is 0 as you only have one section.

If you had two sections it will print out 0, then 1.

As for why numberOfSectionsInTableView: is being called twice, I am unable to give an answer to that one.

Nick