1

几天以来,我遇到了一个无法解决的大问题。

首先,我有一个带有以下代码的登录视图控制器:

@implementation MMConnectionViewController
@synthesize login, password, activityIndicator, mainVC;


- (BOOL)textFieldShouldReturn:(UITextField *)aTextField 
{
 [aTextField resignFirstResponder];

 [self performSelectorOnMainThread:@selector(startRolling) withObject:nil waitUntilDone:NO];

 [NSThread detachNewThreadSelector:@selector(connect) toTarget:self withObject:nil];

 return YES;
}


- (void)viewWillAppear:(BOOL)flag {
    [super viewWillAppear:flag];
    [login becomeFirstResponder];
 login.keyboardAppearance = UIKeyboardAppearanceAlert;
 password.keyboardAppearance = UIKeyboardAppearanceAlert;
 [self setTitle:@"Monaco Marine"];
 UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout"
                    style:UIBarButtonItemStyleBordered
                   target:nil
                   action:nil];
 self.navigationItem.backBarButtonItem = backBarButtonItem;
 [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
 [backBarButtonItem release];
}

- (void)connect {

 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

 mainVC = [[MMMainViewController alloc] initWithLogin:login.text password:password.text connectPass:@"1" navigationController:self.navigationController nibName:@"MMMainViewController" bundle:nil];


 if (mainVC) {
  [self performSelectorOnMainThread:@selector(dataLoadingFinished) withObject:nil waitUntilDone:YES];
 }

 [pool release];
}

- (void)dataLoadingFinished {
 self.stopRolling;
 [self.navigationController pushViewController:mainVC animated:YES];
}

- (void)showAlertWithMessage:(NSString *)message {
 self.stopRolling;
 NSLog(@"%@",message);
 UIAlertView *warning = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:[NSString stringWithFormat:@"%@",message] delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:nil];
 [warning show];
 [warning release];
}

- (void)startRolling {
 [activityIndicator startAnimating];
}

- (void)stopRolling {
 [activityIndicator stopAnimating];
}


- (void)viewDidLoad {
 [login becomeFirstResponder];
}

- (void)dealloc {
 [login release],login=nil;
 [password release],password=nil;
 [activityIndicator release],activityIndicator=nil;
    [super dealloc];
}

之后,有 MMMainViewController 与此代码:

@implementation MMMainViewController
@synthesize login, password, connectPass, navigationController, accountVC;


- (void)viewDidLoad {

 // Set a title for each view controller. These will also be names of each tab
 accountVC.title = @"Account";

 accountVC.tabBarItem.image = [UIImage imageNamed:@"icon_user.png"];

 self.view.frame = CGRectMake(0, 0, 320, 480);

 // Set each tab to show an appropriate view controller
 [self setViewControllers:
  [NSArray arrayWithObjects:accountVC, nil]];

 [navigationController setNavigationBarHidden:NO animated:NO];

 UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Menu"
                   style:UIBarButtonItemStyleBordered
                  target:nil
                  action:nil];
 self.navigationItem.backBarButtonItem = backButton;

 [backButton release];


 [self setTitle:@"Menu"];

}



// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithLogin:(NSString *)l password:(NSString *)p connectPass:(NSString *)c navigationController:(UINavigationController *)navController nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

 UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
 contentView.backgroundColor = [UIColor whiteColor];
 self.view = contentView;
 [contentView release];

 login = l;
 password = p;
 connectPass = c;
 navigationController = navController;

 if (!accountVC)
  accountVC = [MMAccountViewController alloc];

 [self.accountVC
  initWithNibName:@"MMAccountViewController" bundle:nil];

 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 return self;


}

- (void)dealloc {
 [connectPass release];
 [login release];
 [password release];
    [super dealloc];
}

从 MMMainViewController 加载的层 MMAccountViewController 是一个基本的视图控制器,其中没有任何内容。


现在的问题是,有时当加载我的选项卡式视图控制器并返回登录视图控制器时,屏幕会冻结并出现错误消息 (NSZombieEnabled = YES):

*** -[CALayer retain]: message sent to deallocated instance 0xd0199d0

这就是我所拥有的,我真的看不出我错在哪里。

还有什么想法?

感谢那些帮助我的人!

4

2 回答 2

5

你在某处过度释放了某些东西。您可能希望在 Instruments 中运行您的应用程序以检查它可能发生的位置(XCode: Run->Run With Performance Tool->Leaks 将为您提供所需的设置 afaik)。我在您的代码中看不到任何内容,但是您自己说您“大致”使用了此代码,因此它可能不在程序的这一部分中。

更新:我仍然看不到您在某处过度释放了某些东西......我很确定问题不在这部分代码中。如果您还没有发现问题,您可能想尝试创建一个测试用例,即尝试模仿此程序行为并重现错误的小程序。如果你可以在一个小程序中重现它,我会看看。

于 2010-07-13T15:43:31.097 回答
0

我也遇到了同样的问题,问题是我正在为 rightNavigationItem 分配一个 UIButton 并释放该按钮实例,我只是删除了发布代码并开始工作。

于 2011-07-19T06:01:23.030 回答