Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate UIButton title after receiving reply from SKProductsRequest for showing in-app purchases price
    text
    copied!<p>I'm trying to create two buttons whose label is initially set as a default value. The two buttons are managed by a popOverViewController, in which the viewDidLoad method initialise all the controls. I also have another method called addButtons that gets executed by the AppDelegate after receiving a valid response from Apple's servers containing products descriptions and prices.</p> <p>My problem is that I can't get the label updated with that method.</p> <p>My viewDidLoad method in the popOverViewController is:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // Add a label to the popover's view controller. button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(button1Week:) forControlEvents:UIControlEventTouchDown]; NSString *priceWeekly = [NSString stringWithFormat:@"weekly subscription"]; [button setTitle:priceWeekly forState:UIControlStateNormal]; button.frame = CGRectMake(0.0, 0.0, 200.0, 50.0); [button2 addTarget:self action:@selector(button1Month:) forControlEvents:UIControlEventTouchDown]; [button2 setTitle:@"monthly subscription" forState:UIControlStateNormal]; button2.frame = CGRectMake(0.0, 55.0, 200.0, 50.0); [self.view addSubview:button]; [self.view addSubview:button2]; } </code></pre> <p>and my update label method, of which I'm sure it gets called at the right time, is:</p> <pre><code>-(void)addButtons { [self.button setTitle:@"updated label" forState:UIControlStateNormal]; [self.button2 setTitle:@"updated label 2" forState:UIControlStateNormal]; } </code></pre> <p>can you please check my code and suggest the right way to update the labels? Basically I want to initialize the controls with a default label because of the waiting time between controls creation and server response.</p> <p>UPDATE:</p> <p>I have updated the code as follows, but still everything that's inside the addButtons method gets executed as I have an NSLog to check, but the button title still remains as created in viewdidload</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // Add a label to the popover's view controller. UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; ilManifestoAppDelegate *delegate = (ilManifestoAppDelegate*)[[UIApplication sharedApplication] delegate]; [button addTarget:self action:@selector(button1Week:) forControlEvents:UIControlEventTouchDown]; // [button setTitle:priceWeekly forState:UIControlStateNormal]; button.frame = CGRectMake(0.0, 0.0, 200.0, 50.0); [button2 addTarget:self action:@selector(button1Month:) forControlEvents:UIControlEventTouchDown]; // [button2 setTitle:@"monthly subscription" forState:UIControlStateNormal]; button2.frame = CGRectMake(0.0, 55.0, 200.0, 50.0); // [self addButtons]; NSString *weekPrice = [NSString stringWithFormat:@"settimanale a %@",delegate.priceWeek]; [button setTitle:weekPrice forState:UIControlStateNormal]; [button2 setTitle:@"updated label 2" forState:UIControlStateNormal]; NSLog(@"week price %@", weekPrice); [self.view addSubview:button]; [self.view addSubview:button2]; } -(void)addButtons { UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoDark]; [button setTitle:@"modificato" forState:UIControlStateNormal]; [self.view addSubview:button]; NSLog(@"addButtons executed"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload