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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:42:44+00:00 2026-06-08T00:42:44+00:00

I’m facing a very strange behavior of UIBarButtonItem . I have been able to

  • 0

I’m facing a very strange behavior of UIBarButtonItem.

I have been able to reproduce the bug in a test app whose code has been pasted below.

On my first view I have a label displaying a GUID, a button to go to an empty second view, and a UIBarButtonItem. If I click it its color changes from green to red and vice versa and the GUID updates.

Here is how to reproduce it:

  • go to the second view
  • raise a memory warning (in the Simulator Hardware menu, but works the same with a real memory warning on the device)
  • go back to the first one
  • click the UIBarButtonItem

The UIBarButtonItem is not refreshing even if it was before and logs show everything seems correct.

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    @private
    BOOL _isGreenNotRed;
}

@property (weak, nonatomic) IBOutlet UIBarButtonItem *aButton;
@property (weak, nonatomic) IBOutlet UILabel *aGUID;
@end

ViewController.m

#import "ViewController.h"
#import "AFHTTPClient.h"
#import "AFHTTPRequestOperation.h"

@interface ViewController ()
- (NSString *)generateUUID;
- (void)refreshView;
@end

@implementation ViewController
@synthesize aButton;
@synthesize aGUID;

- (NSString *)generateUUID
{
    CFUUIDRef theUUID = CFUUIDCreate(NULL);
    CFStringRef string = CFUUIDCreateString(NULL, theUUID);
    CFRelease(theUUID);
    return (__bridge_transfer NSString *)string;
}

-(void)refreshView {
    NSLog(@"Refreshing first view");

    if(self->_isGreenNotRed) {
        [self.aButton setTintColor:[UIColor colorWithRed:0. green:0.8 blue:0. alpha:1.]];
        NSLog(@"Button should be green");
    }
    else {
        [self.aButton setTintColor:[UIColor colorWithRed:0.8 green:0. blue:0. alpha:1.]];
        NSLog(@"Button should be red");
    }

    self->_isGreenNotRed = !self->_isGreenNotRed;

    NSString *guid = [self generateUUID];

    [self.aGUID setText:guid];
    NSLog(@"GUID should be %@", guid);
}

- (IBAction)aButtonClick:(id)sender {
    [self refreshView];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self->_isGreenNotRed = YES;
    [self refreshView];
}

- (void)viewDidUnload
{
    [self setAButton:nil];
    [self setAGUID:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"Going to second view");
}

@end

And the storyboard :

storyboard

It affects Simulator 5.0 and 5.1, and Device on 5.1.1

EDIT : by logging the value of self.aButton I saw it became nil after the memory warning, due to the weak keyword. But how can I reassign it ? Shouldn’t the SDK do it by itself ? And why is aGUID still available ?

EDIT : here is a log. we can see aButton becomes nil.

2012-07-19 14:39:14.716 test[934:f803] Refreshing first view
2012-07-19 14:39:14.718 test[934:f803] Button <UIBarButtonItem: 0x68b89d0> should be green
2012-07-19 14:39:14.719 test[934:f803] GUID label <UILabel: 0x6dbe580; frame = (49 291; 222 48); text = '08960AFD-F98A-4FBA-9A6E-C...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x6dbe5f0>> should be 08960AFD-F98A-4FBA-9A6E-C548E753F259
2012-07-19 14:39:18.690 test[934:f803] Refreshing first view
2012-07-19 14:39:18.692 test[934:f803] Button <UIBarButtonItem: 0x68b89d0> should be red
2012-07-19 14:39:18.692 test[934:f803] GUID label <UILabel: 0x6dbe580; frame = (49 291; 222 48); text = 'EBB41B52-46D1-4CAE-BF0E-B...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x6dbe5f0>> should be EBB41B52-46D1-4CAE-BF0E-B0679BC1F0EE
2012-07-19 14:39:19.946 test[934:f803] Refreshing first view
2012-07-19 14:39:19.949 test[934:f803] Button <UIBarButtonItem: 0x68b89d0> should be green
2012-07-19 14:39:19.949 test[934:f803] GUID label <UILabel: 0x6dbe580; frame = (49 291; 222 48); text = '8E802026-E825-4219-9CCA-5...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x6dbe5f0>> should be 8E802026-E825-4219-9CCA-5106BF65BDA0
2012-07-19 14:39:33.353 test[934:f803] Going to second view
2012-07-19 14:39:40.811 test[934:f803] Received memory warning.
2012-07-19 14:39:43.471 test[934:f803] Refreshing first view
2012-07-19 14:39:43.472 test[934:f803] Button (null) should be green
2012-07-19 14:39:43.473 test[934:f803] GUID label <UILabel: 0x6896570; frame = (49 291; 222 48); text = '3D4933A8-908B-4570-BD55-6...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x68b0130>> should be 3D4933A8-908B-4570-BD55-68C298F6E621
2012-07-19 14:39:48.649 test[934:f803] Refreshing first view
2012-07-19 14:39:48.650 test[934:f803] Button (null) should be red
2012-07-19 14:39:48.651 test[934:f803] GUID label <UILabel: 0x6896570; frame = (49 291; 222 48); text = '9CDCF065-12C2-4F16-9464-A...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x68b0130>> should be 9CDCF065-12C2-4F16-9464-A5CE202BE7CA
  • 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-08T00:42:45+00:00Added an answer on June 8, 2026 at 12:42 am

    Is refreshView getting called after the memory warning?

    Try removing the code that sets the views to nil in viewDidUnload? Does it solve the problem?

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from

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.