rahulbsb
rahulbsb

Reputation: 115

issue with numberOfSectionsInTableView method

- (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 before tableView method is called. I can't understand why.

The other thing that 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.

Doesn't the section parameter get updated since I set it as 1 previously? I mean at runtime the tableView:numberOfRowsInSection: method is called internally so obviously section parameter is supposed to hold some value.

Isn't that the case?

Upvotes: 1

Views: 2194

Answers (3)

Hussain Shabbir
Hussain Shabbir

Reputation: 15015

Try like this inspite of returning 1:-

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {
    NSLog(@"Test1");
     return [yourArray count];
 }

Upvotes: 0

Akash Malhotra
Akash Malhotra

Reputation: 1106

Sections and rows in tableViews are just like arrays, they start with 0.

Upvotes: 0

Meenakshi
Meenakshi

Reputation: 1162

Number of section is the count of sections in the TableView & the index of row & section starts from 0.

Upvotes: 1

Related Questions