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 9240481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:11:49+00:00 2026-06-18T08:11:49+00:00

Is it possible to replace a cell view for the selected cell? I have

  • 0

Is it possible to replace a cell view for the selected cell? I have registered my controller as a data source and delegate. Requests for cell views, row numbers, selection status, etc, all come in nicely. In the cell selection callbacks, I’m trying to have the table view reload the cell with a new view (not the actual data!). Basically, I want the cell view to expand and show more of the underlying data, if it is selected. The problem is that I have no clue how to make the table view ask my controller for a new view. I can see that the view is requesting the cell height, but nothing more.

Calling reloadData on the view works, but it’s inefficient and comes with a set of its own problems (animation possibilities, maintaining selection state, etc).

  • 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-06-18T08:11:50+00:00Added an answer on June 18, 2026 at 8:11 am

    Here is the approach I would take to do this.

    @property (nonatomic, strong) NSIndexPath *selectedIndexPath;
    

    Set a property of type NSIndexPath to your controller to store which index path was selected.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        self.selectedIndexPath = indexPath;
        [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation: UITableViewRowAnimationNone];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        if ([indexPath compare:self.selectedIndexPath] == NSOrderedSame) {
            // Create your custom cell here and return it.
        }
        else {
            // Should create a normal cell and return it.
        }
    }
    

    Exactly. Note too that you probably want to deselect. Here’s the full code in Swift. Use selectedIndexPath in cellForRowAtIndexPath as appropriate.

    // Selecting TableViewController
    import UIKit

    class SelectingTableViewController: UITableViewController
    {
    internal var selectedIndexPath:NSIndexPath? = nil

    override func viewDidLoad()
        {
        super.viewDidLoad()
        tableView.estimatedRowHeight = 68.0
        tableView.rowHeight = UITableViewAutomaticDimension
    
        self.clearsSelectionOnViewWillAppear = false;
        }
    
    override func tableView
        (tableView:UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath)
            {
            print("did select....")
    
            // in fact, was this very row selected,
            // and the user is clicking to deselect it...
            // if you don't want "click a selected row to deselect"
            // then on't include this clause.
            if selectedIndexPath == indexPath
                {
                print("(user clicked on selected to deselect)")
                selectedIndexPath = nil
                tableView.reloadRowsAtIndexPaths(
                    [indexPath],
                    withRowAnimation:UITableViewRowAnimation.None)
    
                tableView.deselectRowAtIndexPath(indexPath, animated:false)
                return
                }
    
            // in fact, was some other row selected??
            // user is changing to this row? if so, also deselect that row
            if selectedIndexPath != nil
                {
                let pleaseRedrawMe = selectedIndexPath!
                // (note that it will be drawn un-selected
                // since we're chaging the 'selectedIndexPath' global)
                selectedIndexPath = indexPath
                tableView.reloadRowsAtIndexPaths(
                    [pleaseRedrawMe, indexPath],
                    withRowAnimation:UITableViewRowAnimation.None)
                return;
                }
    
            // no previous selection.
            // simply select that new one the user just touched.
            // note that you can not use Apple's willDeselectRowAtIndexPath
            // functions ... because they are freaky
            selectedIndexPath = indexPath
            tableView.reloadRowsAtIndexPaths(
                [indexPath],
                withRowAnimation:UITableViewRowAnimation.None)
    
            }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to replace part of the data in a cell. For example,
Possible Duplicate: Replace individual list elements in Haskell? I have managed to make some
Possible Duplicate: Replace while keeping certain words in vi/vim Let's say I have several
I have a cell that has string IDs. I need to replace them with
Possible Duplicate: replace all occurrences in a string I have this string: 12-3-02 And
Possible Duplicate: Replace only first match using preg_replace I have a string as follows:
Is it possible to replace a table cell without deleting it with javascript or
Possible Duplicate: Replace letters in a string I have some texts anh yêu em
Possible Duplicate: Replace multiple whitespaces with single whitespace in JavaScript string I have used
Possible Duplicate: replace in vb.net How to put data containing double-quotes in string variable?

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.