Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make specific UITableViewCell to be visible on screen while having more rows in UITableView

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?

like image 337
Krishna Avatar asked Feb 06 '12 09:02

Krishna


People also ask

How do you get the indexPath row when a button in a cell is tapped?

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.

How do you add a space between UITableView cells?

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.

How can we use a reusable cell in UITableView?

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.


1 Answers

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.

like image 75
Nico teWinkel Avatar answered Sep 30 '22 20:09

Nico teWinkel