Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory warning doesn't work properly
    primarykey
    data
    text
    <p>I'm practicing on how TabViewcontroller works. Now I have 2 subclasses of UIViewcontroller. One is HypnosisViewController , the other is TimeViewController. What I wanted to check is how <strong>-(void)viewDidLoad</strong> works when IOS simulator gets memory warning. And I did</p> <ol> <li>Built and ran the app</li> <li>The console said "HypnosisViewcontroller loaded its view."</li> <li>Switched the other tab (TimeViewController)</li> <li>Saw the message in the console. It says "TabViewcontroller loaded its view"</li> <li>Did the simulator memory warning command in IOS simulator</li> <li>The console said "HypnoTime Received memory warning."</li> <li>Switched back to the HypnosisViewcontroller to see whether the console says "HypnosisViewcontroller loaded its view." again.</li> </ol> <p><strong>So the problem here is HypnosisViewcontroller is not destroyed and created again. (Because I can't see the log message when I switch back to HypnosisViewcontroller.)However I leaned the view not on the screen should be destroyed during the memory warning.</strong></p> <p>Did I miss something? Thanks in advance!</p> <p>HypnosisViewController.m:</p> <pre><code>#import "HypnosisViewController.h" #import "HypnosisView.h" @implementation HypnosisViewController -(void)loadView { //Create a view CGRect frame = [[UIScreen mainScreen] bounds]; HypnosisView *v = [[HypnosisView alloc] initWithFrame:frame]; // Set it as *the* view of this view controller [self setView:v]; } -(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle { self = [super initWithNibName:nil bundle:nil]; if(self){ //Get the tab bar item UITabBarItem *tbi = [self tabBarItem]; //Give it a label [tbi setTitle:@"Hypnosis"]; //Create a UIImage from a file //This will use Hypno@2x.png on retina display devices UIImage *i = [UIImage imageNamed:@"Hypno.png"]; // Put that image on the tab bar item [tbi setImage:i]; } return self; } -(void)viewDidLoad { // Always call the super implmetaion of viewDidload [super viewDidLoad]; NSLog(@"HypnosisViewcontroller loaded its view"); } @end </code></pre> <p>TimeViewController.m:</p> <pre><code>#import "TimeViewController.h" @implementation TimeViewController -(IBAction)showCurrentTime:(id)sender { NSDate *now = [NSDate date]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setTimeStyle:NSDateFormatterMediumStyle]; [timeLabel setText:[formatter stringFromDate:now]]; [timeLabel2 setText:[formatter stringFromDate:now]]; } -(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle { // Call the superclass's designated initializer self = [super initWithNibName:nil bundle:nil]; //Get a pointer to the application bundle object // NSBundle *appBundle = [NSBundle mainBundle]; // self = [super initWithNibName:@"TimeViewController" //bundle:appBundle]; if(self){ //Get the tab bar item UITabBarItem *tbi = [self tabBarItem]; //Give it a label [tbi setTitle:@"Time"]; //Create a UIImage from a file //This will use Time@2x.png on retina display devices UIImage *i = [UIImage imageNamed:@"Time.png"]; // Put that image on the tab bar item [tbi setImage:i]; } return self; } -(void)viewDidLoad { // Always call the super implmetaion of viewDidload [super viewDidLoad]; NSLog(@"TimeViewcontroller loaded its view"); // [[self view] setBackgroundColor:[UIColor greenColor]]; } @end </code></pre> <p><img src="https://i.stack.imgur.com/Ii1ri.png" alt="enter image description here"><img src="https://i.stack.imgur.com/bYeJS.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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