views:

751

answers:

2

I am new to iPhone SDK.

I have a UIScrollView and a UITableView on it. The UITableView has 4 cells. I use UIPageControl for pagination.

When user selects, the cell gets highlighted and when the user scrolls to the next page the cell stays highlighted.

I tried [tableView reloadData] and after the call I could still see the selected row on the UITableView which I do not understand.

Should I redraw the UIScrollView?

Is there any way of clearing up the selection?

Thanks, R

A: 

Are you using a UIScrollView and/or UIPageControl to scroll the UITableView? UITableView doesn't need either of those for scrolling.

From your description, it sounds like you are not reusing cells properly.

Put up some code and we'll have more to work with. You might have to show us your UITableView subclass .m file.

mahboudz
I am using UIScrollView AND UIPageControl. I think my question is if I want multiple pages and each page has a UITableView, do I really need a UIScrollView? I just took the "PageControl" example and added a UITableView.
Rosatta Drew
I think I understand. You have one TableView inside a ScrollView that is page controlled by PageControl to show sibling views of the TableView? Does this TableView get populated with a different set of data for each page that you page to? Or are you somehow wanting to display each of the 4 rows of the TabelView in a different page?
mahboudz
That is exactly right. Yes the table gets populated with a different set of data for each page. I do not have problem populating these data, I get different set of data. The problem is in selection, once the user selects a cell and moves to the next page the row which was selected in the previous page stays selected. If I some how programatically unselect the selection in the previous page also gets unselected. I want the page to remember the selection. Thank for your assistance. -R
Rosatta Drew
+1  A: 

I've seen this behavior when you include a table view within another view. If you do this, you need to manually clear up the current selection. You can do this by calling the following:

[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:animated];

where 'animated' is set to fit your needs.

If you include the table view directly (as another person noted, you a table view already scrolls just fine all by itself, likely making your UIScrollView unnecessary and bad form to boot), this behavior is automatic.

Ken Wootton