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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:39:19+00:00 2026-05-29T19:39:19+00:00

The idea is user can click a button Add Country, Country picker will come

  • 0

The idea is user can click a button Add Country, Country picker will come up, and whatever user selects from picker will be added as label/buttons (USA delete) under Add Country button. These new delete buttons, if clicked will remove themselves and their label.

I can already get the value from Country picker and create a button using the code from here How do I create a basic UIButton programmatically?

My problem is the button is just being positioned on top of existing elements. I would like created buttons to be under the Add Country button or under previously created buttons. Whatever element was previously below Add Country button should move down.

I don’t even know what search terms I should use to google this. I’ve thought of using uitableview to contain the newly created buttons and it would expand somehow but I’ve had no luck with this either. I am using storyboard by the way.

EDIT: Added relevant code:

    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    // get text of selected option
    NSString *pickedText;
    if ([pickerView tag] == 201) {
        pickedText = [arrCountries objectAtIndex:row];
    }
    else if([pickerView tag] == 202) {
        pickedText = [arrLanguages objectAtIndex:row];
    }

    // create button
    UIButton *countryButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [countryButton addTarget:self
                      action:@selector(removeCountry:)
            forControlEvents:UIControlEventTouchUpInside];
    [countryButton setTitle:pickedText forState:UIControlStateNormal];
    countryButton.frame = CGRectMake(0, 210.0, 160.0, 40.0);
    [self.view addSubview:countryButton];

    // hide picker
    [countryPicker setHidden:YES];
    [languagePicker setHidden:YES];

}

- (void)removeCountry:(UIButton *)countryButton
{
    [countryButton removeFromSuperview];
}

EDIT2: Updated code where elements are moving down except for previously dynamically added button.

// create button
    UIButton *countryButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [countryButton addTarget:self
                      action:@selector(removeCountry:)
            forControlEvents:UIControlEventTouchUpInside];
    [countryButton setTitle:pickedText forState:UIControlStateNormal];

    CGRect newFrame = addCountryButton.frame;
    newFrame.origin.y = newFrame.origin.y + addCountryButton.frame.size.height + countryButton.frame.size.height;
    countryButton.frame = newFrame;

    [self.view addSubview:countryButton];

    // move elements down
    [elementsBelowAddCountry enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
        CGRect newFrame = [obj frame];
        newFrame.origin.y = newFrame.origin.y + countryButton.frame.size.height;
        [obj setFrame:newFrame];
        NSLog(@"object %@", obj);

    }];

    [elementsBelowAddCountry setByAddingObject:countryButton]; 
    // this doesn't work. new countryButton is set on top of previous countryButton
  • 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-29T19:39:21+00:00Added an answer on May 29, 2026 at 7:39 pm

    I like the tableView option as well, it is pretty clean. Here are two more alternatives:

    You can create an exact copy (B) of your view (A) in the storyboard, including the new subview (countryButton) in B with everything else moved down. Then when user selects to add country in A, transition (segue) to B with a fade (not a confusing push). The maintenance problem is that anytime you update view A you’ll have to remember to update B as well. Once nice thing with this option is that you can change the spacing between lines if you want (so as to not move anything off screen).

    Another single-view alternative is to maintain a set of all the items you want to move if the addCountry is clicked (build the list in viewDidLoad). When selected, enumerate the objects with enumerateObjectsUsingBlock: with something like this:

    CGRect newFrame = self.frame;
    newFrame.origin.y = newFrame.origin.y + countryButton.frame.size.height + 10;
    self.frame = newFrame;
    

    If countryButton is deleted, do the same thing except decrease the y.

    I kind of like the 2nd option. This is good too because if you put the enumeration into an animate block it will look slick.

    Enjoy,

    Damien

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

Sidebar

Related Questions

I have a button that the user can click which sends them to the
So we have a program that the user can use by copying text from
My idea is to have a view that is showing the user when something
The idea behind this small project of mine is to have an user enter
Is it good idea to have application engine written in c++ and user interface
Any idea why this won't work? I m getting tags a user has set
First i was wondering if this is a good idea, essentially i have user
Any idea on how can I track users bookmarking event? I want to find
I am writing a password-reset page for my website. Here's my idea: a. User
I'm trying to expand on an idea from someone else's question, and running into

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.