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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:49:32+00:00 2026-06-09T19:49:32+00:00

I need to be able to remove a button from a view and add

  • 0

I need to be able to remove a button from a view and add a different one. My code looks like this:

-(void)UpdatePromoBanner:(NSString*)value{
    [button setTitle:@"newer text" forState:UIControlStateNormal];
    for (UIView *subView in emptyViewController.view.subviews)
    {
        if(subView.tag == 99) {
            //--remove button and add an updated one
            NSLog(@"Remove button?");
            [subView removeFromSuperview];
            //[subView.superview addSubview:button];
        }
    }
    NSLog(@"event called");

}

-(void)AddPromoBannerToBottom:(UIView*)view {

    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self 
               action:@selector(aMethod:)
     forControlEvents:UIControlEventTouchDown];
    [button setTitle:lblForBannerButton forState:UIControlStateNormal];
    button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
    button.tag = 99;

    [view addSubview:button];
}

The emptyViewController is just a plain empty view controller. I’m adding a button in the middle. I hit the NSLog ok that checks the tag, but the view does not get removed. I should mention I’m using a thread thats firing the updatepromobanner every 5 secs.

  • 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-09T19:49:34+00:00Added an answer on June 9, 2026 at 7:49 pm

    Oscar is right. You have to update the interface on the main thread. Figured I’d add in some code to help.

    Replace:

    [subView removeFromSuperview];
    

    With:

    [subView performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:NO];
    

    And I think you should be good to go without changing anything else.

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

Sidebar

Related Questions

I need to be able to test 27 different web apps in isolation, so
I need a user to be able to perform these actions: Click an Add
I need to remove the selected items from a ListBox in asp.net. I keep
I have a situation like this I'm using a single activity but with different
I have a situation here where I need to be able to add, delete
I have a simple css3 button and I need to align this button inside
I need to be able to add javascript to an existing classic asp page
I need to be able to run RegLoadKey() on a remote machine, and it
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to

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.