Problem in UITableViewDelegate - RowSelected gives wrong NSIndexPath
Posted
by
vlad259
on Stack Overflow
See other posts from Stack Overflow
or by vlad259
Published on 2011-02-01T10:05:21Z
Indexed on
2011/02/18
15:25 UTC
Read the original article
Hit count: 229
I have a UITableViewSource which I have subclassed. I'm overriding GetCell and using my own subclassed cells, like so:
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
MarketItem item=_tableItems[indexPath.Section].Items[indexPath.Row];
MarketCell cell=tableView.DequeueReusableCell(_cellIdentifier) as MarketCell;
if (cell==null)
{
cell=new MarketCell(UITableViewCellStyle.Subtitle,_cellIdentifier,item);
}
// decorate the cell
// ...
return cell;
}
This works but when I get events in my UITableViewDelegate, the index path gets me the wrong cell (events like AccessoryButtonTapped, WillSelectRow etc).
The Section and Row numbers look correct but when I do a
tableView.CellAt(indexPath)
I get the wrong cell. (The row and section numbers again look correct.)
Things to note:
- The table is constantly being updated - items arrive in a different thread which are then InvokeOnMainThread'd
- Although the table is constantly updated, rows and sections are only added - nothing is re-ordered or deleted
- If I pause the updates when I get a 'WillSelectRow', it doesn't help
- Most interestingly (but not a shippable solution) if I make a new cell each time rather than doing DequeueReusableCell, it works correctly.
I can't help thinking it's a stupid bug of my own making but can't find it. Any help would be most gratefully received!
© Stack Overflow or respective owner