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

  • SEARCH
  • Home
  • 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 4343668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:47:11+00:00 2026-05-21T11:47:11+00:00

I’m figuring out the correct way to reuse cells in a UITableView and I

  • 0

I’m figuring out the correct way to reuse cells in a UITableView and I would know if the mechanism I’m using is correct.

The scenario is the following.

I’ve a UITableView that displays a list of data obtained from a web service.

_listOfItems = e.Result as List<Item>;

where _listOfItems is an instance variable.

This list is passed to a class that extends UITableViewSource. Obviously this class override GetCell method to visualize data in this manner:

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{       
    UITableViewCell cell = tableView.DequeueReusableCell(_cID);

    Item item = _listOfItems[indexPath.Row];

    int id = item.Id;

    if (cell == null)
    {   
        cell = new UITableViewCell(UITableViewCellStyle.Value1, _cID);

        cell.Tag = id;

        _cellControllers.Add(id, cell);
    }
    else
    {
        bool vb = _cellControllers.TryGetValue(id, out cell);

        if(vb)
        {
            cell = _cellControllers[id];
        }

        else
        {
            cell = new UITableViewCell(UITableViewCellStyle.Value1,  _cID);             
            cell.Tag = id;

            _cellControllers.Add(id, cell);
        }
    }

    cell.TextLabel.Text = item.Title;

    return cell;
}

where

_cID is an instance variable identifier for the cell

string _cID = "MyCellId";

_cellControllers is a dictionary to store cell and the relative id for an Item instance

Dictionary<int, UITableViewCell> _cellControllers;

I’m using the dictionary to store cells bacause when a row is tapped, I have to retrieve the id for the cell tapped (through cell.Tag value), do some other operation – i.e.retrieve other some data from the service – and then update that cell again with new values. In this case each cell has to be unique.

So, my question is:

Is this the right manner to reuse cell or is it possible to figured out another solution to reuse cell and guaranteeing each tap for a cell is unique?

I hope it’s all clear 🙂 Thank you in advance. Regards.

  • 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-21T11:47:12+00:00Added an answer on May 21, 2026 at 11:47 am

    I think what you are doing here is a bit too much. Especially the part where you are holding extra references to cells in a Dictionary.

    I would do it differently. The DequeueReusableCell method is there so that you can retrieve any existing cell, but not necessarily the values it contains. So something like this will suffice:

    public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
    {
    
        int rowIndex = indexPath.Row;
        Item item  = _listOfItems[rowIndex];
    
        UITableViewCell cell = tableView.DequeueReusableCell(_cID);
    
        if (cell == null)
        {
            cell = new UITableViewCell(UITableViewCellStyle.Value1, _cID);
        }
    
        // Store what you want your cell to display always, not only when you are creating it.
        cell.Tag = item.ID;
        cell.TextLabel.Text = item.Title;
    
        return cell;
    }
    

    Then, in the RowSelected method, change your data source:

    public override void RowSelected (UITableView tableView, NSIndexPath indexPath){
        // Do something here to change your data source _listOfItems[indexPath.Row] = new Item();
    }
    

    If I understand correctly what you want to do, this solution is better.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping 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.