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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:15:32+00:00 2026-06-03T04:15:32+00:00

I have a method makeButtons (posted here), which is removing all buttons in the

  • 0

I have a method makeButtons (posted here), which is removing all buttons in the screen and adding them again. This works fine in viewDidLoad and viewDidAppear. I am accessing information from a webservice which is telling me I need a new button. When I am calling [self makebuttons] from that method, nothing happends, until I move forth and back with my NavigationController forcing viewDidAppear to do the work again. My question is why? I am doing exactly the same, unless it’s not called from viewDidAppear, but from doneGettingInformation.

- (void) viewDidAppear:(bool) animated {
    [self makebuttons]; // Works great!
}

- (void) doneGettingInformation : (ASIFormDataRequest *) request {
    NSString *response = [request responseString];
    [[self.temp.userInfo objectForKey:@"spillider"] addObject:response];
    [self makebuttons]; // This gets called, but nothing changes in the view itself.
}

- (void) makeButtons {
    NSLog(@"kjort");
    int newAntall = [[self.temp.userInfo objectForKey:@"spillider"] count];
    for (UIButton * button in gameButtons) {
        NSString *tag = [NSString stringWithFormat:@"%i",button.tag];
        [button removeFromSuperview];
        if ([webviews objectForKey:tag]) {
            [[webviews objectForKey:tag] removeFromSuperview];
            [webviews removeObjectForKey:tag];
        }
    }
    [gameButtons removeAllObjects];
    scroller.contentSize = CGSizeMake(320, 480);
    if (newAntall > 3) {
        CGSize scrollContent = self.scroller.contentSize;
        scrollContent.height = scrollContent.height+((newAntall-3)*BUTTON_HEIGTH);
        self.scroller.contentSize = scrollContent;
    }
    int y = 163;
    self.nyttSpillKnapp.frame = CGRectMake(BUTTON_X, y, BUTTON_WIDTH, 65);
    for (int i=0; i<newAntall; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setBackgroundImage:[UIImage imageNamed:@"knapp_midt"] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:@"knapp_midt"] forState:UIControlStateHighlighted];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button.titleLabel setFont:[UIFont systemFontOfSize:15]];
        button.frame = CGRectMake(BUTTON_X, y, BUTTON_WIDTH, BUTTON_HEIGTH);
        button.enabled = YES;
        UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                                    action:@selector(deleteButton:)];
        swipe.direction = UISwipeGestureRecognizerDirectionRight;
        [button addGestureRecognizer:swipe];
        button.tag = [[[self.temp.userInfo objectForKey:@"spillider"] objectAtIndex:i] intValue];
        NSString * tittel = [NSString stringWithFormat:@"spill %@",[[self.temp.userInfo objectForKey:@"spillider"] objectAtIndex:i]];
        [button setTitle:tittel forState:UIControlStateNormal];
        UIButton *subButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        subButton.transform = CGAffineTransformMakeRotation(M_PI_2);
        subButton.tag = i;
        CGRect subframe = CGRectMake(230, 5, subButton.frame.size.width, subButton.frame.size.height);
        subButton.frame = subframe;
        CGRect myframe = self.nyttSpillKnapp.frame;
        myframe.origin.y = myframe.origin.y+BUTTON_HEIGTH;
        self.nyttSpillKnapp.frame = myframe;
        [subButton addTarget:self action:@selector(clickGameButton:) forControlEvents:UIControlEventTouchUpInside];
        [button addSubview:subButton];
        [gameButtons addObject:button];
        [self.scroller addSubview:button];
        y += BUTTON_HEIGTH;
    }
}

To sum up, it only works if I am changing viewcontrollers back and forth causing viewWillAppear to get called. Why is that?

I am sorry for my messy methods.

Thanks

  • 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-03T04:15:33+00:00Added an answer on June 3, 2026 at 4:15 am

    If you change the contents of the view outside of the initial view appearing process or layout changes, it’s your responsibility to call setNeedsDisplay and inform the run loop that it needs to be redrawn.

    The system will ask the view to draw it’s contents initially or during layout changes which is why it works as part of the process to first show the view. During that initial process, the viewWill/DidAppear delegates will get called.

    From the UIView class reference:

    The View Drawing Cycle

    View drawing occurs on an as-needed basis. When a view is first shown,
    or when all or part of it becomes visible due to layout changes, the
    system asks the view to draw its contents
    . For views that contain
    custom content using UIKit or Core Graphics, the system calls the
    view’s drawRect: method. Your implementation of this method is
    responsible for drawing the view’s content into the current graphics
    context, which is set up by the system automatically prior to calling
    this method. This creates a static visual representation of your
    view’s content that can then be displayed on the screen.

    When the actual content of your view changes, it is your
    responsibility to notify the system that your view needs to be
    redrawn. You do this by calling your view’s setNeedsDisplay or
    setNeedsDisplayInRect: method of the view. These methods let the
    system know that it should update the view during the next drawing
    cycle. Because it waits until the next drawing cycle to update the
    view, you can call these methods on multiple views to update them at
    the same time.

    EDIT:

    Also, make sure done getting images is not called on a background thread. You can’t edit views on a background thread. If it is you can prepare all the data on a bg thread but then call makeButtons on on the main thread (performSelectorOnMainThread or use blocks.

    See GCD, Threads, Program Flow and UI Updating

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

Sidebar

Related Questions

I have method to which I pass an object. In this method I check
I have method which create background thread to make some action. In this background
I have method (which is part of IMyInteface) like this: interface IMyInterface { void
I create small application which is media player. I have method where I have
i have a method which takes in a DotNetOpenAuth (formally known as DotNetOpenId) Response
I have this method that changes an larger image source on click. I need
I have method that download and resize image according to screen size to fit
I have method for converting array of Booleans to integer. It looks like this
I have method called SColl. This method invokes a webservice. When using parallel.invoke I
I have method which return the latitude of the location public double[] getlat(){ double

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.