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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:00:27+00:00 2026-05-25T11:00:27+00:00

I am trying to create an app with a built in chat feature. I

  • 0

I am trying to create an app with a built in chat feature. I am trying to make it work similarly to the Messages application, with one major difference. Instead of there being a camera icon for MMS I would like to add a UISegmentedControl to manually switch between which person you are in the conversation. I have it working pretty well except whenever you change identity on the switch, it changes the identity of everything said previously in the chat. I’m really stuck up on this and any help would be greatly appreciated.

    NSString *text = [messages objectAtIndex:indexPath.row];
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(240.0f, 480.0f) lineBreakMode:UILineBreakModeWordWrap];

UIImage *balloon;



if(segmentedControl.selectedSegmentIndex == 0) {

    balloonView.frame = CGRectMake(320.0f - (size.width + 28.0f), 2.0f, size.width + 28.0f, size.height + 15.0f);
    balloon = [[UIImage imageNamed:@"green.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
    label.frame = CGRectMake(307.0f - (size.width + 5.0f), 8.0f, size.width + 5.0f, size.height); 
}
else if(segmentedControl.selectedSegmentIndex == 1) {
    balloonView.frame = CGRectMake(0.0, 2.0, size.width + 28, size.height + 15);
    balloon = [[UIImage imageNamed:@"grey.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
    label.frame = CGRectMake(16, 8, size.width + 5, size.height);

}



balloonView.image = balloon;
label.text = text;

return cell;

}

 -(IBAction) segmentedControlIndexChanged {
switch (self.segmentedControl.selectedSegmentIndex) 
{
    case 0: (self.segmentedControl.selectedSegmentIndex == 0);


    case 1: (self.segmentedControl.selectedSegmentIndex == 1);

        break;

    default:
        break;
}

}

Image 1
Image 2

So over all, what I’m asking is how can I modify this, to make it so when i switch the UISegmentedControl it changes the messages typed while the switch is in this state only.
Thank you 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-05-25T11:00:29+00:00Added an answer on May 25, 2026 at 11:00 am

    This is what I think is wrong. First, you need to change the IBAction function, because it doesn’t do anything. This is what it translates to:

    -(IBAction) segmentedControlIndexChanged {
      if(self.segmentedControl.selectedSegmentIndex == 0) 
      {
          self.segmentedControl.selectedSegmentIndex == 0;
      } 
          else if (self.segmentedControl.selectedSegmentIndex == 1)
      {
          self.segmentedControl.selectedSegmentIndex == 1;
      }
    }
    

    I hope you can agree with me that this does nothing; what it’s doing is checking if the index is what you want it to be, then if it is it just checks it again. Maybe you wanted it to be changed (one equal sign only, but that won’t make sense either)??, but either way that won’t solve your problem.

    Second, create a boolean in your class (call it leftSideConversation), initialize it to TRUE if the selectedSegmentedIndex is initially set to 0, and FALSE if it’s set to 1. Then modify the IBAction part of your code to look like this:

    -(IBAction) segmentedControlIndexChanged {
      if(self.segmentedControl.selectedSegmentIndex == 0) 
      {
          leftSideConversation = TRUE;
      } 
          else if (self.segmentedControl.selectedSegmentIndex == 1)
      {
          leftSideConversation = FALSE;
      }
    }
    

    Third, what you need to do is create identities … you need to know who is typing what. I can’t help you with this, because I do not know how it was programmed, but you need to figure out a way. The following part in your code is what’s wrong as well. The segment index remains the same throughout the conversation, and is only changed when you press the button. Hence, the conversation is always on one side, and judging from the snapshots you provided, it seems this has always been the case. Change this part of your code from:

    if(segmentedControl.selectedSegmentIndex == 0) {
    
    balloonView.frame = CGRectMake(320.0f - (size.width + 28.0f), 2.0f, size.width + 28.0f, size.height + 15.0f);
    balloon = [[UIImage imageNamed:@"green.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
    label.frame = CGRectMake(307.0f - (size.width + 5.0f), 8.0f, size.width + 5.0f, size.height); 
    }
    else if(segmentedControl.selectedSegmentIndex == 1) {
        balloonView.frame = CGRectMake(0.0, 2.0, size.width + 28, size.height + 15);
       balloon = [[UIImage imageNamed:@"grey.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
        label.frame = CGRectMake(16, 8, size.width + 5, size.height);
    }
    

    to look something along the lines of this:

    if(myText == leftSideConversation) {
    
    balloonView.frame = CGRectMake(320.0f - (size.width + 28.0f), 2.0f, size.width + 28.0f, size.height + 15.0f);
    balloon = [[UIImage imageNamed:@"green.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
    label.frame = CGRectMake(307.0f - (size.width + 5.0f), 8.0f, size.width + 5.0f, size.height); 
    }
    else {
        balloonView.frame = CGRectMake(0.0, 2.0, size.width + 28, size.height + 15);
       balloon = [[UIImage imageNamed:@"grey.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
        label.frame = CGRectMake(16, 8, size.width + 5, size.height);
    }
    

    where myText is a boolean that accompanies each of the messages that are typed, such that myText is set to TRUE if you send the message and FALSE if you receive it. Good Luck!

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

Sidebar

Related Questions

Trying to get production application to work with hsqldb. The application is built with
I'm trying to create an app for Android that simply sends a command to
I'm trying to create a rails app, but somethings going wrong, I'm getting a
I am trying to create a simple app that displays a list of items
I'm trying to create a WinForms app that takes a screenshot on a set
I'm very new to Flash Builder and am trying to create an AIR app
Trying to create my first iPhone app that would play back audio. When I
Im trying to create a simple pan and zoom app using silverlight 4, but
I'm trying to create a Palm OS app to check a web site every
I am trying to create a utility keystroke app so i can do things

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.