代码如下:
@interface A : UIViewController <UITextFieldDelegate>
{
UITextField *inputName;
}
@property (nonatomic,retain) UITextField *inputName;
@end
....m文件
@implementation A
@synthesize inputName;
- (void)dealloc
{
if(inputName != nil)
{
[inputName release];
inputName = nil;
}
[super dealloc];
}
//A类的dealloc函数调用后报错。EXC_BAD_ACCESS(code = 1,address=0xd000000c)
pushViewController代码如下:
aa = [[A alloc] init];
[self.navigationController pushViewController:aa animated:YES];
[aa release];
aa = nil;
popToViewController 代码如下:
NSArray *array = self.navigationController.viewControllers;
B *app = (B *)([array objectAtIndex:[array count] - 3]);
[self.navigationController popToViewController:(UIViewController *)app animated:YES];
//[self.navigationController popToRootViewControllerAnimated:YES];
在执行popToViewController 或popToRootViewControllerAnimated,返回最顶层后,A类的dealloc函数调用到了,然后报错。EXC_BAD_ACCESS(code = 1,address=0xd000000c)错误
在init里面 inputName = [[UITextField alloc]initWithFrame:CGRectMake(10, Img.size.height + Img.size.height / 2, Img.size.width,Img.size.height)];
inputName.delegate = self;
[self.view addSubview:inputName];
[inputName release];
在这个地方inputName release有什么问题吗?如果我把[inputName release];这条语句去掉,dealloc里面就不报错了,我跑了retainCount语句,addSubview之后retainCount是2,在 dealloc里面retainCount输出也是2,我的整个做法哪里有问题吗?
@interface A : UIViewController <UITextFieldDelegate>
{
UITextField *inputName;
}
@property (nonatomic,retain) UITextField *inputName;
@end
....m文件
@implementation A
@synthesize inputName;
- (void)dealloc
{
if(inputName != nil)
{
[inputName release];
inputName = nil;
}
[super dealloc];
}
//A类的dealloc函数调用后报错。EXC_BAD_ACCESS(code = 1,address=0xd000000c)
pushViewController代码如下:
aa = [[A alloc] init];
[self.navigationController pushViewController:aa animated:YES];
[aa release];
aa = nil;
popToViewController 代码如下:
NSArray *array = self.navigationController.viewControllers;
B *app = (B *)([array objectAtIndex:[array count] - 3]);
[self.navigationController popToViewController:(UIViewController *)app animated:YES];
//[self.navigationController popToRootViewControllerAnimated:YES];
在执行popToViewController 或popToRootViewControllerAnimated,返回最顶层后,A类的dealloc函数调用到了,然后报错。EXC_BAD_ACCESS(code = 1,address=0xd000000c)错误
在init里面 inputName = [[UITextField alloc]initWithFrame:CGRectMake(10, Img.size.height + Img.size.height / 2, Img.size.width,Img.size.height)];
inputName.delegate = self;
[self.view addSubview:inputName];
[inputName release];
在这个地方inputName release有什么问题吗?如果我把[inputName release];这条语句去掉,dealloc里面就不报错了,我跑了retainCount语句,addSubview之后retainCount是2,在 dealloc里面retainCount输出也是2,我的整个做法哪里有问题吗?