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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:30:33+00:00 2026-06-18T02:30:33+00:00

This may be a long question in order I’ll be able to explain all

  • 0

This may be a long question in order I’ll be able to explain all the problem I’ve encountered.
So, I want to implement such UI functionality:

enter image description here

enter image description here

So I have a UITableView which is implemented in one file and it’s cells which is implemented in other file TableViewCell.m
And I need after clicking on button read more to expand UILabel with text mesage as on the second screen and after clicking on close message button to restore UILabel and consequently resize TableView cell (this is one button i only change images of it). So in order to resize UILabel I use [UILabel sizeToFit] and change label.numberOfLines from 3 to 0 (iOS 6 feature as far as I know).And here code of creating cells:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath {
CPNTalkCell *cell = (CPNTalkCell *)[tableView  dequeueReusableCellWithIdentifier:kCellIdentifier];
NSString *modelId = [[models objectAtIndex:indexPath.row] valueForKey:@"modelId"];
NSDictionary *model = [[models objectAtIndex:indexPath.row] valueForKey:@"model"];
return [self setupCell:cell forModel:model withId:modelId];
}

In setupCell method I do additional adjustments and in CPNTalkCell the cell is described vi IB.
And here the code of button ReadMore event handler where I try to resize cell and label:

-(void)ResizeLabel:(id)sender
{
  UIView* sender_button = (UIView*)sender;
  UIButton* _resizingSenderButton = (UIButton*)sender;
  CGRect _button_before = _resizingSenderButton.frame;
  NSIndexPath* indexPath = [listView indexPathForCell:(UITableViewCell*)[[ sender_button superview]superview ]]; //In such an ugly way may be i
  //access NSIndexpath of the current cell from
  // which button was clicked
  CPNTalkCell *cell = (CPNTalkCell*)[listView cellForRowAtIndexPath:indexPath];
  if (cell.messageLabel.numberOfLines==3) {
  [self.listView  beginUpdates];
  cell.messageLabel.numberOfLines=0;
  [cell.messageLabel sizeToFit];
  _button_before.origin.y = cell.messageLabel.frame.origin.y+ cell.messageLabel.frame.size.height+7;
  _resizingSenderButton.frame=_button_before;
 [_resizingSenderButton setBackgroundImage:[UIImage imageNamed:@"readmore2.png" ] forState:UIControlStateNormal];
 [cell sizeToFit];
 //  [self.listView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
 [self.listView reloadData];
 [self.listView endUpdates];
 }
  else
 {
  cell.messageLabel.numberOfLines = 3;
  [self.listView  beginUpdates];
  [cell.messageLabel sizeToFit];
   CGRect _button_after = _resizingSenderButton.frame;
  _button_after.origin.y = cell.messageLabel.frame.origin.y+ cell.messageLabel.frame.size.height+7;
  _resizingSenderButton.frame=_button_after;
  [_resizingSenderButton setBackgroundImage:[UIImage imageNamed:@"readmore1.png" ] forState:UIControlStateNormal];
  [cell sizeToFit];
  [self.listView reloadData];
  //[self.listView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
  [self.listView endUpdates];
  }
   }

So this code work and after clicking cells resize to fit the text and it’s length but works strange – sometimes buttons disappear or appear on the text after scrolling the list buttons also may disappear or even text.I use reloadData when I change cell – i know it’s not optimal, but as you see I’ve commented code of reloading of one cell because it works even more strange or not from the first clicking.
I also overload heightForRowatIndexPath:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *modelId = [[models objectAtIndex:indexPath.row] valueForKey:@"modelId"];
NSDictionary *model = [[models objectAtIndex:indexPath.row] valueForKey:@"model"];
CPNTalkCell *cell = [_cells objectForKey:modelId];

if (cell == nil) {
    cell = [self setupCell:nil forModel:model withId:modelId];
}

return cell.rowHeight;
}

But in it i describe initial cell parameters before clicking on a button via calling of rowHeight described in TalkCell file!

I know it’s a long question and I sometimes explain not all clear but I think iOS experts will be able to understand my problem and propose solution of this problem. I really need a help because I try to solve this problem not for a one day.

Great thanks in advance!

  • 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-18T02:30:36+00:00Added an answer on June 18, 2026 at 2:30 am

    You need to overload heightForRowAtIndexPath to return the appropriate value based on the expanded cell

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *mode
    
        lId = [[models objectAtIndex:indexPath.row] valueForKey:@"modelId"];
        NSDictionary *model = [[models objectAtIndex:indexPath.row] valueForKey:@"model"];
        CPNTalkCell *cell = [_cells objectForKey:modelId];
    
        if (cell == nil) {
            cell = [self setupCell:nil forModel:model withId:modelId];
        }
    
        if ( indexPath == expandedIndexPath )//save the expanded cell's index path somewhere
        {
            return expandedCellHeight;
        }
    
        return cell.rowHeight;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I want to apologize for such a long question. You don't
this may sound pretty straight forward, but still I want to post this question
This may be a long shot question.. I am working on an application that
This post may seem overly long for just the short question at the end
The question may be long but the problem is actually simple. I have 3
I have to work with strings which may contain Lat/Long data, like this: $query
This may be a stupid question but I have a code with the following
This may be a simple question but I can;t find the answer anywhere. Here
this may sound a newbie question anyway Im new to GCD, I'm creating and
This may sound like a very generic question but here it goes. I have

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.