Search code examples
iphoneuitableviewasynchronousdidselectrowatindexpath

iOS: Horizontal UITableView inside another UITableView issues


I want to create a table with horizontal scrolled rows. I have followed Felipe Laso's tutorial in Raywenderlich's blog, here. It works perfectly except for 2 issues.

First, the inner horizontal table should have a dynamic number of cells based on an array fetched asynchronously using ASIHTTPRequest block from the outer vertical table.

//Inner horizontal table number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{    
    //self.articles is being assigned from cell.articles asynchronously from the outer vertical table
    return [self.articles count];
}

The code above gives me an error, if the self.articles hasn't yet been assigned. So how could I determine the number of rows from the outer ASIHTTPRequest block and reload the inner table?

Second, I want to push another view based on each cell's horizontal and vertical indexes.

I have 2 didSelectRowAtIndexPath method in the 2 table, I tried to NSLog the indexpath.row at both tables, the inner table logged the cell's index, however the outer table logged NULL.

So what should I do?


Solution

  • If you haven't read your data in yet, then you don't have any rows, you should return 0. When you have read in your data, then when the read is complete, call reloadData on the list to refresh all the calls. You probably want to push your second view at this time too.