VMCuongOnStackOverflow VMCuongOnStackOverflow - 1 month ago 16
Objective-C Question

Objective-C : Always display 3 rows in UITableView

After scrolling i want my TableView to display like this :



not like this :



and i have set my rowHeight = tableViewHeight / 3:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return CGRectGetHeight(self.tableView.frame)/3;
}

Answer

There are a couple things you need for this. Firstly, you need to detect when the table view has stopped scrolling: How to know exactly when a UIScrollView's scrolling has stopped?

Next, you need to set the scroll view position: How can I set the scrolling position of an UIScrollView?

The position you're going to want to set it might be the tableview contentOffset - (contentOffset % rowHeight) to move it up to show the row partially shown at the top.

Comments