Search code examples
objective-ciosuitableviewloadview

when does -tableView:cellForRowAtIndexPath: get called?


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?


Solution

  • -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];
    }