我有一个很大的问题,因为几天我无法解决。我不知道为什么我的视图被冻结
首先,我有这个代码登录视图控制器:
@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是什么也没有一个基本的视图控制器在里面。
现在的问题是,有时当加载我标签视图控制器和I返回到登录视图控制器,画面冻结和错误与消息(NSZombieEnabled = YES):
*** -[CALayer retain]: message sent to deallocated instance 0xd0199d0
这是我的全部,我真的不知道我错在哪里。
一些更多的想法?
感谢那些帮助我的人!
非常感谢您的回复! 我会试试这个。也许这个问题来自viewcontroller的构造。我没有太多的代码在我的mainViewController.m 我要用第一个viewController编辑我的消息。 – 2010-07-13 15:51:27
我的猜测是这与你发布视图控制器不直接相关。顺便说一下,最好不要使用与Apple命名相同的对象名称,例如:'self.navigationItem.backBarButtonItem = backBarButtonItem;' – iwasrobbed 2010-07-13 16:05:28
好吧,我会尝试制作这个小程序。问题是这个bug可能会随机出现。有时它是在第一次推动之后出现的,有时候是在后面,但总是在相同的视角。是否有可能模拟器或其他外部参数可以改变我的程序的行为? @IWasRobbed你是对的我没有注意到我的对象的名称。我会检查一下。我也不确定:当我有一个视图控制器作为一个类的属性(引用下一个视图控制器),我应该释放它在我的dealloc方法或它被管理的地方? – 2010-07-14 10:28:42