didselectrowatindexpath method not working properly if the tableview has more rows than it can show on ipad screen
When i select a row i hav made didSelectRowAtIndexPath to put a Checkmark indicator. My Table view is present in a popover and has more data that it can accomodate in the screen. The problem is when i scroll down to see more rows the first cell that loads when scroll also has the checkmark indicator.
For example if i have 30 rows in my table view and if i select i row on screen and the screen can accomodate 15 rows. If i scroll to see more rows 16th row also has the checkmark. Similarly if i select 2 row and scroll down 17th row also gets selected.
I need to have only one row selected at a time by user.My didselectrowatindexpth is not working consistenly. If anyone has a proper working vesion please share or suggest me how to get around this problem. Also, i have two sections in my table view. So the user can select only one row from any one of the sections.
My didSelectRowAtIndexPath code.
int newRow = [indexPath row];
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
if (newRow != oldRow || (newRow == 0 && oldRow == 0)) {
UITableViewCell *cell = [bTableView cellForRowAtIndexPath:indexPath];
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
UITableViewCell *oldCell = [bTableView cellForRowAtIndexPath:lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
开发者_JS百科lastIndexPath = indexPath;
Any changes you make to your cells should be reset in cellforrowatindexpath
delegate method as they are reused. So reset before returning cell in this method. And have a variable to hold the selected values and update accordingly. So basically your datasource should be able to hold the values of the selected rows and not the cells.
精彩评论