我不知道为什么我的观点是冻结 [英] I don't know why my view is freezing

查看:235
本文介绍了我不知道为什么我的观点是冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的问题,因为几天,我不能解决。



首先我有一个登录视图控制器与此代码:

  @implementation MMConnectionViewController 
@synthesize login,password,activityIndi​​cator,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:@1navigationController:self.navigationController nibName:@MMMainViewControllerbundle: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消息:[NSString stringWithFormat:@%@,message] delegate:self cancelButtonTitle:@RetryotherButtonTitles:nil];
[warning show];
[warning release];
}

- (void)startRolling {
[activityIndi​​cator startAnimating];
}

- (void)stopRolling {
[activityIndi​​cator stopAnimating];
}


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

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

之后,有这个代码的MMMainViewController:

  @implementation MMMainViewController 
@synthesize登录,密码,connectPass,navigationController,accountVC;


- (void)viewDidLoad {

//为每个视图控制器设置一个标题。这些也将是每个选项卡的名称
accountVC.title = @Account;

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

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

//设置每个选项卡以显示相应的视图控制器
[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];

}



//指定的初始化程序。如果以编程方式创建控制器并想要执行不适合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:@MMAccountViewControllerbundle: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]:消息发送到deallocated实例0xd0199d0 

这是我所有,我真的看不到我错了。 >

还有更多想法?



感谢那些帮助我的人。

解决方案

你在某处过度释放某些东西。您可能想在Instruments中运行您的应用程序,以检查它可能发生的地方(XCode:运行 - >运行与性能工具 - >漏洞将给你需要afaik的设置)。我在代码中看不到任何东西,但你说你自己使用大致这个代码,所以它可能不在你的程序的这一部分。



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


I have a big problem since a few days that I can't solve.

First I have a login view controller with this code :

@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];
}

After, there's MMMainViewController with this code :

@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];
}

The layer MMAccountViewController loaded from MMMainViewController is a basic view controller with nothing in it.


Now the problem is that sometimes when load my tabbed view controller and I go back to the login view controller, the screen freezes and bug with message (NSZombieEnabled = YES) :

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

This is all I have and I really can't see where I'm wrong.

Some more idea?

Thanks for those who help me!

解决方案

You are overreleasing something somewhere. You might want to run your application in Instruments to check where it may be happening (XCode: Run->Run With Performance Tool->Leaks will give you the setup that you need afaik). I can't see anything in your code, but you said yourself that you use "roughly" this code, so it may not be in this part of your program.

Update: I still can't see that you overrelease something somewhere... I'm pretty sure the problem is not within this part of the code. If you haven't found the problem yet, you may want to try and create a test case, that is, a small program that tries to mimic this programs behavior and reproduce the bug. If you can reproduce it within a small program, I'll take a look at that.

这篇关于我不知道为什么我的观点是冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆