Search code examples
iosobjective-cuitableviewuilabelfixed

Label outside of UITableViewCell updating for the cell currently on screen


I would like to implement a fullscreen UITableView in my app which would show only one cell at a time with an image. On top of each cell, I would like to have a few labels with fixed positions, so that when the user swipes to the next cell they stay on their place, only get updated.

What would be the most effective way to implement such functionality?

That's how I would like the end result to look:

enter image description here


Solution

  • You can do this with a full height table view. Just add it in a UIView controller, and add the label to the view controller's view (not to the table view) also. Set paging enabled for your table, and set the row height to the height of the table view. You can get the row of the visible cell with this code, and do whatever you want with that number to update your label,

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
        NSArray *paths = self.tableView.indexPathsForVisibleRows;
        NSInteger row = [paths[0] row];
        ContainerViewController *parent = (ContainerViewController *)self.parentViewController;
        parent.label.text = [NSString stringWithFormat:@"This is picture %d", row];
    }