Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3933694
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:37:49+00:00 2026-05-19T23:37:49+00:00

I have a UITableViewSource which I have subclassed. I’m overriding GetCell and using my

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:37:49+00:00Added an answer on May 19, 2026 at 11:37 pm

    You could try a different approach as demonstrated on: http://simon.nureality.ca/?p=91

    Basically, don’t subclass UITableViewCell but instead subclass UIViewController as “MarketCellController”. This custom controller maintains a standard UITableViewCell as well as your custom stuff and simply adds your custom stuff via AddSubview().

    You create one new controller for each required cell and store them into a dictionary.

    The trick: By assigning unique tags to the cells, you can retrieve the associated controller from the dictionary.

    Quick example:

    Dictionary<int,MarketCellController> controllers = new Dictionary<int,MarketCellController>();
    
    // ...
    
    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) {
      UITableViewCell cell = tableView.DequeueReusableCell(_cellIdentifier);
      MarketCellController cellController;
    
      if (cell == null) {
        cellController = new MarketCellController();
        cell = cellController.Cell;
        controllers.Add(cell.Tag, cellController);
      } else {
        cellController = controllers[cell.Tag];
      }
    
      // Decorate the cell (using Methods of your cellController)
      // ...
    
      return cell;
    }
    

    This could eventually circumvent problems with subclassed UITableViewCells and dequeuing.

    EDIT:

    I just had something else in mind: You seem to be only assinging your items on your MarketCell constructor. However, dequeued cells have their old item set and you need to reset it to the new item after dequeuing.

    Remove the item parameter of the constructor (it’ll be overwritten anyways) and create a public property (or setter) instead. Use that to assign the correct item after fetching the cell (regardless if it was dequeued or newly created). That should do:

    MarketCell cell = tableView.DequeueReusableCell(_cellIdentifier) as MarketCell;
    if (cell == null) {
      cell = new MarketCell(UITableViewCellStyle.Subtitle, _cellIdentifier);
    }
    
    // Assign the correct item
    cell.Item = item;
    // or (whatever you like more):
    // cell.SetItem(item);
    
    // Decorate the cell
    // ...
    
    return cell;
    

    The same goes for my cellController approach as well. No matter if a cell was dequeued or new, you should always reset everything on the cell that could possibly differ from any other cells.

    BTW: If you hard-code your cells to UITableViewCellStyle.Subtitle, you could just omit it from the constructor as well and hard-code it into your MarketCell class.

    As for what the cellController approach is worth: You decouple the UITableViewCell from your custom data and behaviour and thus get a nice layer of separation. Your cell controller does not have to act like a table cell 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have just started using Google Chrome , and noticed in parts of our site,
Have you seen library for flexible working with terminal(Unix like)? I want to implement
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
I have a snippet to create a 'Like' button for our news site: <iframe
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.