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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:53:01+00:00 2026-05-27T01:53:01+00:00

I have an iPhone App with a view which contains 2 buttons. I created

  • 0

I have an iPhone App with a view which contains 2 buttons. I created these buttons in the Interface Builder.

Now I want to add a new button to the view programmatically:

- (void) addButton {
    //allocate the view
    self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

    //set the view's background color
    self.view.backgroundColor = [UIColor whiteColor];

    //create the button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    //set the position of the button
    //button.frame = CGRectMake(100, 10, 50,50);
    button.frame = CGRectMake(100, 100, 10,10);

    //set the button's title
    [button setTitle:@"Click Me!" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(myButtonClick:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];

    //add the button to the view
    [self.view addSubview:button];  
}

Done, and it works, however the other 2 buttons which were added in Interface Builder have disappeared. The new button is quite small and only covers a small bit of the view.

Could anyone tell me where my buttons are going to?

  • 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-27T01:53:02+00:00Added an answer on May 27, 2026 at 1:53 am

    Why are you allocating another view? It will replace the old one and everything it contains.
    Just create the button.

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

Sidebar

Related Questions

i have an iPhone app in which i have several images. These images add
I have a small iPhone app which has a button on the first view.
My Setup: In my iPhone app, I have a loading View (which is an
I have a MonoTouch iPhone app which has a UITableViewController as it's main view
In my view of my iPhone app, I have added one sub view, which
I have an iPhone app which has a tabBarController as the root view controller
I have an iPhone app that shows a simple view (View 1) that has
I have an iPhone app that hides the status bar. However, my main view
In my iPhone Core Data app I have it configured in a master-detail view
I have an iphone app where I call these three functions in appDidFinishLaunching: glMatrixMode(GL_PROJECTION);

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.