iPhone делегат и контроллер - PullRequest
2 голосов
/ 16 января 2010

Я играл с простым приложением для iphone и решил поместить оператор NSLog в свободные места как контроллера, так и делегата, но ни один из них не распечатать на консоли Xcode?

// ДЕЛЕГАТ ПРИМЕНЕНИЯ

#import "iPhone_buttonFunAppDelegate.h"
#import "iPhone_buttonFunViewController.h"

@implementation iPhone_buttonFunAppDelegate

@synthesize window;
@synthesize viewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {       
    // Override point for customization after app launch
    NSLog(@"applicationDidFinishLaunching ...");
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"AWT:");
}

- (void)dealloc {
    NSLog(@"-DEL-"); // << Does not print?
    [viewController release];
    [window release];
    [super dealloc];
}
@end

// КОНТРОЛЛЕР ПРОСМОТРА

#import "iPhone_buttonFunViewController.h"

@implementation iPhone_buttonFunViewController
@synthesize statusText;

-(IBAction)buttonPressed:(id) sender {
    NSString *title;
    NSString *newText;

    title = [sender titleForState:UIControlStateNormal];
    newText = [[NSString alloc] initWithFormat:@"%@ button pressed.", title];
    [statusText setText:newText];
    [newText release];
    NSLog(@"Button Press ... %@", title);
}

-(void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
    NSLog(@"-1-");
}

-(void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    NSLog(@"-2-");
    self.statusText = nil;
}

-(void)dealloc {
    NSLog(@"-CON-"); // << Does not print?
    [statusText release];
    [super dealloc];
}
@end

1009 * Гэри *

Ответы [ 2 ]

5 голосов
/ 17 января 2010

Это оптимизация во время выполнения касания Какао. Определенные освобождения не выполняются в конце программы, поскольку вся программа собирается завершиться, и они все равно будут уничтожены.

0 голосов
/ 16 января 2010

На эту проблему с NSLog (...) может ответить на этот другой вопрос о стековом потоке о applicationWillTerminate:

Удачи.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...