0

I have a UITableView of downloadable items and I used another UITableView for the download item info. How can I reload the UiTableView of all UITableViewCell?

I tried using [downloadList reloadData]; but it only refreshes the big table.

Edit: I'm trying to do something like this: jsfiddle.net/WrNFU. I want details aligned properly but the problem is that the title can be too long and I'm not sure how many lines the title is going to use. I used a second table because of heightForRowAtIndexPath function which enables me to adjust the title row's height.

Answer:

Using the code I found here: iPad: Iterate over every cell in a UITableView?

    for (int section = 0; section < [downloadList numberOfSections]; section++) {
        for (int row = 0; row < [downloadList numberOfRowsInSection:section]; row++) {
            NSIndexPath* cellPath = [NSIndexPath indexPathForRow:row inSection:section];
            UITableViewCell* cell = [downloadList cellForRowAtIndexPath:cellPath];

            UITableView *tempTableView = (UITableView *)[cell viewWithTag:110];
            [tempTableView reloadData];
        }
    }
Community
  • 1
  • 1
Jace
  • 439
  • 1
  • 7
  • 19
  • why you are not using one table view custom cell? that contains 4 labels, 2 static text and 2 are dynamic. Among those make a title label no.of.lines to 3 and handle the height of the table. – Ganapathy Nov 12 '13 at 12:13

1 Answers1

1

Using one single UITableView (no need to use nested tableviews) you can treat each item (book?) as a single UITableViewCell and handle the different size for content.

Yu need to calculate the height of the UITableViewCell and set

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

so that the tableview knows the size of the content. You have of course to size also the labels to fit the text.

There is also

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);

which can be used to reload the single cells when the download is finished.

It is still not clear why you would want to reload a single cell, is the download for each item started when the view is presented? Are you downloading just the text displayed or complete files? I have the feeling it could be handled in an easier way.

Fr4ncis
  • 1,387
  • 1
  • 11
  • 23
  • how can I access the inner tableview? using tags? Since I can't use IBOutlet on the inner tableview. – Jace Nov 12 '13 at 11:14
  • Tags could be a good idea. But are you sure you need to have inner tableviews? Couldn't you use sections? – Fr4ncis Nov 12 '13 at 11:23
  • I'm trying to display something like this on my inner table view: Title: XXXXXXXX XXXXXXXX Author: XXXXX – Jace Nov 12 '13 at 11:25
  • Isn't a simple UITableViewCell enough? – Fr4ncis Nov 12 '13 at 11:28
  • I didn't know that the comment section changes the alignment. I'm trying to do something like this: http://jsfiddle.net/WrNFU/ . It's the only way I know to keep those text display neatly aligned. – Jace Nov 12 '13 at 11:35
  • So you have multiple rows each row contains title and author name right? – Ganapathy Nov 12 '13 at 11:37
  • You can edit the question posting the code, in this case anyway I would use a single table view (corresponding to ** tag) and for each tr I would use a UITableViewCell, then inside you may align the UILabels however you like. There is no need to nest UITableViews. UITableViews are good to create list-like tables, not matrix-like tables (UICollectionViews are better then), but anyway in this case a UITableView is more than enough.
    – Fr4ncis Nov 12 '13 at 11:42
  • 1
    well the problem is that the title could be short or long. I don't know how many lines its going to take to display it fully. – Jace Nov 12 '13 at 11:48
  • I have successfully recalculated the UITableViewCell for the inner table. I'm just having problem reloading that particular table. – Jace Nov 12 '13 at 11:57
  • Yes I'm downloading the information from a web server and it takes time to get all the data ready. That's why I opt to use table reload when the data becomes available. – Jace Nov 12 '13 at 12:03
  • why you are not using one table view custom cell? that contains 4 labels, 2 static text and 2 are dynamic. Among those make a title label no.of.lines to 3 and handle the height of the table. – Ganapathy Nov 12 '13 at 12:13
  • If I do that, a gap will appear if the title is shorter than 3 lines. – Jace Nov 12 '13 at 12:15