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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:08:29+00:00 2026-05-26T07:08:29+00:00

I am building an app to go alongside a web app I’ve built, which

  • 0

I am building an app to go alongside a web app I’ve built, which features a threaded comment system.

I’m wondering what the best approach to building this threaded view would be. Is there a relatively easy way to build an accordion style control?

I really like how the Alien Blue app does it, and the UI & UX is very smooth:

enter image description here

  • Does anyone have any idea how these are built?
  • Would making custom UIViews added as subviews be the best approach? If so, how would you implement ‘collapse’ style functionality?
  • 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-26T07:08:30+00:00Added an answer on May 26, 2026 at 7:08 am

    I’d suggest creating a UIView subclass to contain each comment. It should have a toggle button to expand / collapse. On toggling open i’d set the frame size to the size of the content (plus any padding). It would contain an array of sub-comments, for each one you’d add the UIView subclasses to itself at expand time (And remove when collapsing) which would initially be collapsed (and so just appear as the toggle button). Collapsing is just the reverse, remove the subviews, set the frame to be the hight of the toggle button (plus padding)

    As each comment view knows its size, you can put the whole thing in a UIScrollView with content-size set to the sum of the comment views sizes allowing scrolling regardless of expanded / contracted nature.

    A partial implementation for this idea:

    Comment.h

    #import <Foundation/Foundation.h>
    
    @interface Comment : NSObject {
        NSMutableArray* subComments;
        NSString* comment;
    }
    
    @property (nonatomic, retain) NSMutableArray* subComments;
    @property (nonatomic, retain) NSString* comment;
    
    @end
    

    Comment.m

    #import "Comment.h"
    
    @implementation Comment 
    @synthesize comment, subComments;
    
    -(id)init
    {
        self = [super init];
        if (self)
        {
            subComments = [[NSMutableArray alloc] init];
        }
        return self;
    }
    
    @end
    

    CommentView.h

    #import <UIKit/UIKit.h>
    
    @interface CommentView : UIView {
        UIButton* toggle;
        NSMutableArray* subComments;
        NSString* commentText;
        UITextView* comment;
        BOOL expanded;
    }
    @property (strong, nonatomic) NSMutableArray* subComments;
    @property (strong, nonatomic) NSString* commentText;
    
    
    - (void) expand;
    - (void) collapse;
    - (void) toggleState;
    
    @end
    

    CommentView.m

    #import "CommentView.h"
    
    
    @implementation CommentView
    @synthesize subComments,commentText;
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
        }
        [self setBackgroundColor:[UIColor whiteColor]];
        expanded = NO;
        toggle = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [toggle setTitle:@"Toggle" forState:UIControlStateNormal];
        [toggle addTarget:self action:@selector(toggleState) forControlEvents:UIControlEventTouchUpInside];
        CGRect curentFrame = self.frame;
        curentFrame.size.height = toggle.frame.size.height + 10;
        [self setFrame:curentFrame];
    
        curentFrame = toggle.frame;
        curentFrame.origin.y = 5;
        curentFrame.origin.x = 5;
        [toggle setFrame:curentFrame];
        [self addSubview:toggle];
        [self collapse];
    
        return self;
    }
    
    - (void) toggleState
    {
        if (expanded)
        {
            [self collapse];
        }
        else
        {
            [self expand];
        }
    }
    
    - (void) expand
    {
        comment = [[UITextView alloc] init];
        [comment setEditable:NO];
        [comment setText:commentText];
        [self addSubview:comment];
        CGRect curentFrame = comment.frame;
        curentFrame.size.height = comment.contentSize.height;
        curentFrame.origin.x = toggle.frame.size.width + toggle.frame.origin.x + 10;
        curentFrame.size.width = self.frame.size.width - curentFrame.origin.x;
        curentFrame.origin.y = toggle.frame.size.height + toggle.frame.origin.y + 10;
        [comment setFrame:curentFrame];
    
        curentFrame = self.frame;
        curentFrame.size.height += comment.frame.size.height + 10;
        [self setFrame:curentFrame];
        float height = comment.frame.origin.y + comment.frame.size.height;
        for (NSObject* o in subComments)
        {
            CommentView* subComment = [[CommentView alloc] initWithFrame:CGRectMake(comment.frame.origin.x,height,0,self.frame.size.width)];
            [self addSubview:subComment];
            height += subComment.frame.size.height;
            curentFrame = self.frame;
            curentFrame.size.height += subComment.frame.size.height;
            [self setFrame:curentFrame];
            [self bringSubviewToFront:subComment];
        }
        expanded = YES;
    }
    
    - (void) collapse
    {
        for (UIView* v in [self subviews])
        {
            [v removeFromSuperview];
        }
    
        CGRect curentFrame = self.frame;
        curentFrame.size.height = toggle.frame.size.height + 10;
        [self setFrame:curentFrame];
    
        curentFrame = toggle.frame;
        curentFrame.origin.y = 5;
        curentFrame.origin.x = 5;
        [toggle setFrame:curentFrame];
        [self addSubview:toggle];
    
        expanded = NO;
    
    }
    
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
    }
    */
    
    @end
    

    ViewContoller.m (Example usage)

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        CommentView* mainCommentView = [[CommentView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    
        Comment* mainComment = [[Comment alloc] init];
        [mainComment setComment: @"Lorem Ipsum 1"];
    
        Comment* sub1 = [[Comment alloc] init];
        [sub1 setComment: @"Lorem Ipsum 1-1"];
        Comment* sub11 = [[Comment alloc] init];
        [sub11 setComment: @"Lorem Ipsum 1-1-1"];
        [[sub1 subComments] addObject:sub11];
    
        Comment* sub2 = [[Comment alloc] init];
        [sub2 setComment: @"Lorem Ipsum 1-2"];
        Comment* sub12 = [[Comment alloc] init];
        [sub12 setComment: @"Lorem Ipsum 1-2-1"];
        [[sub2 subComments] addObject:sub12];
    
        [[mainComment subComments] addObject:sub1];
        [[mainComment subComments] addObject:sub2];
    
        [mainCommentView setCommentText:[mainComment comment]];
        [mainCommentView setSubComments:[mainComment subComments]];
    
        self.view = mainCommentView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app that makes use of hotkeys, it's a web UI to
I'm building an app in Rails 3. I currently have a user model which
I'm building an app in CodeIgniter. I have an invoice form which uses jQuery
I'm building app using GAE and wanted to use Django for that. Which patch
So I'm building an app using PHP and MongoDB which will have a fair
I`m building simple app which shows information about most car brands. I have rootViewController
I'm building an app which would have to have the ability to show my
I'm building an app which is going to have to handle and store a
I'm building an app that takes a photo and then e-mails it. For this
I'm building an app which relies on the gyroscope which is only available on

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.