I am having 20 rows in a table view, and I have designed (or say resized) UITableView in half of the screen (Using IB) and in half screen I am showing the stuff related to particular UITableViewCell. Which cell's details are going to be shown in the half screen is decided runtime. I want the cell being visible while loading the view for say second last cell.
How can I achieve this?
add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.
The way I achieve adding spacing between cells is to make numberOfSections = "Your array count" and make each section contains only one row. And then define headerView and its height. This works great.
For performance reasons, a table view's data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView(_:cellForRowAt:) method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.
I found the easiest way to ensure that a whole cell is visible is to ask the tableview to make sure that the rect for the cell is visible:
[tableView scrollRectToVisible:[tableView rectForRowAtIndexPath:indexPath] animated:YES];
An easy way to test it is just to put that into -(void)tableView:didSelectRowAtIndexPath:
- tapping any cell will then scroll it into place if it's partially hidden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With