Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 2, 2013, 05:12 AM   #1
MickeyT
macrumors member
 
Join Date: Apr 2010
Location: Newcastle, United Kingdom
Simulate memory warning not working

I have a UITabBarController containing two view controllers.

The purpose of an exercise I am following is to demonstrate that you should never reference a view controller's view in the initialiser of a view controller.

To demonstrate the point, I am asked to add the following code to the view controller's initWithNibName method:

Code:
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    
    self = [super initWithNibName:nil bundle:nil];
    
    if (self) {
        
        UITabBarItem *tbi = [self tabBarItem];
        
        [tbi setTitle:@"Time"];
        
        UIImage *i = [UIImage imageNamed:@"Time"];
        [tbi setImage:i];
        
        //This is the offending line
        [[self view] setBackgroundColor:[UIColor greenColor]];
    
    }
    
    return self;
    
}
I am then asked to go to the simulator, select the "Time" tab, go back to the other tab and then simulate a memory warning. Then, when I return to the "Time" tab, the background is supposed to not be green anymore because only the viewDidLoad method is called in this situation, not the initialiser.

However, when I do this the viewController's view doesn't seem to get destroyed because the background is still green.

I am also directed to override the viewDidUnload method, and in here an NSLog instruction is supposed to write something to the console. However, it never does, which indicates that viewDidUnload is never getting called.

For information, the memory warning simulation does seem to do something because "Received memory warning" appears in the console.

Does anyone know why this is, please? I am fairly confident I've followed the book to the letter.

Could it be something to do with iOS 6? The book was written when iOS 5 was the latest OS version. I can't seem to test this theory in the simulator because I inadvertently built the app as an iOS 6 app, and the new layout constraints that appear as part of building the XIB file cause the iOS 5 simulator to crash.

Thank you.
__________________
13" Macbook Pro, 2.4 GHz, 8 GB RAM; 16GB iPhone 5, 32GB iPad 3

Last edited by MickeyT; Feb 2, 2013 at 06:37 AM.
MickeyT is offline   0 Reply With Quote
Old Feb 2, 2013, 06:36 AM   #2
MickeyT
Thread Starter
macrumors member
 
Join Date: Apr 2010
Location: Newcastle, United Kingdom
I've helped myself here....I must have been looking at the book when I typed this out the first time and missed the popup in the attached screenshot.

Please consider this one resolved.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-02-02 at 12.33.18.png
Views:	10
Size:	30.7 KB
ID:	394080  
__________________
13" Macbook Pro, 2.4 GHz, 8 GB RAM; 16GB iPhone 5, 32GB iPad 3
MickeyT is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 06:26 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC