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:[実行]->[パフォーマンスツールで実行]->[リーク]により、必要なセットアップが提供されます)。あなたのコードには何も見えませんが、あなたはこのコードを「大まかに」使用していると自分自身に言ったので、それはあなたのプログラムのこの部分にないかもしれません。

更新:あなたがどこかで何かをオーバーリリースしているのをまだ見ることができません...問題はコードのこの部分にないことはかなり確信しています。問題がまだ見つかっていない場合は、テストケース、つまり、このプログラムの動作を模倣してバグを再現しようとする小さなプログラムを作成してみてください。小さなプログラムで再現できたら見ていきます。

于 2010-07-13T15:43:31.097 に答える
0

私も同じ問題に遭遇しました。問題は、UIButton を rightNavigationItem に割り当ててそのボタン インスタンスを解放していたことでした。リリース コードを削除して作業を開始しました。

于 2011-07-19T06:01:23.030 に答える