0

I am having this issue with loading up table content in UITableViewController. I have created UITableViewController without the xib. In loadView I am calling a function which generates the array of data to be displayed. And from that array in tableView:cellForRowAtIndexPath: I am trying to load the cells. But somehow I am getting nothing on table. Besides that when I set break point for about call, it seems not get called. Can anyone tell what am I doing wrong here?

Costique
  • 23,712
  • 4
  • 76
  • 79
slonkar
  • 4,055
  • 8
  • 39
  • 63
  • 1
    A little code from `loadView` method would help. Other than that - once you created that view try calling `reloadData` on your table. – Eimantas Feb 11 '12 at 19:17
  • 1
    Are you returning correct values from the `numberOfSectionsInTableView` and `numberOfRowsInSection:` methods of your tableView delegate? – jonkroll Feb 11 '12 at 19:21
  • no its not. I am getting 0 for number of rows. – slonkar Feb 11 '12 at 19:33

3 Answers3

4

-tableView:cellForRowAtIndexPath: gets called whenever new cell is needed, whether when first filling the screen with cells, or when a new cell is scrolled into the screen, but it will never get called if you haven't returned a proper number of sections and rows for your table view, as they will be 0 by default.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [yourArray count];
}
Filip Radelic
  • 26,607
  • 8
  • 71
  • 97
0

cellforrowatindexpath is called when building the table. Have you set the delegate of the table to self? Have you added to your .h?

Darren
  • 10,182
  • 20
  • 95
  • 162
  • 2
    It's the dataSource that must be set. Delegate is responsible for row selection, not display. – Eimantas Feb 11 '12 at 19:17
  • my .h is something like this classname: UITableViewController {} – slonkar Feb 11 '12 at 19:20
  • If you have created a `UITableViewController` subclass, they delegate and dataSource are already set up properly, just make sure you return right number of sections and rows and that you call `[self.tbleView reloadData];` when you update your data source (add/remove/change objects in array). – Filip Radelic Feb 11 '12 at 19:25
0

as eimantas said, you have to set the "dataSource" delegate of your UITableView = (pointing to) yourClass with the tableView:cellForRowAtIndexPath method...

it's the method called whenever a new cell is needed (the first time you see your table it creates a needed number of cells to cover the whole height of your table height), then it's called when user scroll the table (not to create new cells, but to reuse the old cells with the new data needed)

meronix
  • 6,175
  • 1
  • 23
  • 36