Iphone 线程1:EXC\u坏访问(代码=1,地址=0x70745092)
正如标题所说,我的代码中出现了这个错误。除了通常的Iphone 线程1:EXC\u坏访问(代码=1,地址=0x70745092),iphone,objective-c,ios6,Iphone,Objective C,Ios6,正如标题所说,我的代码中出现了这个错误。除了通常的(lldb)之外,没有输出。它所指的线是 0x10df051:movl 8(%edx),%edi0x10df051:movl 8(%edx),%edi 代码本身是 DeltaViewController *deltaview = [[DeltaViewController alloc] initWithNibName:@"DeltaViewController" bundle:nil]; 它发生在我在选择器中选择一个对象时,它应该添加一个子视图
(lldb)
之外,没有输出。它所指的线是
0x10df051:movl 8(%edx),%edi0x10df051:movl 8(%edx),%edi
代码本身是
DeltaViewController *deltaview = [[DeltaViewController alloc] initWithNibName:@"DeltaViewController" bundle:nil];
它发生在我在选择器中选择一个对象时,它应该添加一个子视图。
deltaview
是DeltaViewController类型,因此它是控制器,而不是视图。将其添加为self.view([self.view addSubview:deltaview.view];)的子视图后,可以释放deltaview
。然后,每当您向deltaview
发送一个方法(在DeltaViewController中实现)时,您当然会收到这个EXC\u BAD\u访问错误
一个简单的解决方案:只需将deltaview
(实际上,它应该是deltaViewController
)声明为iVar而不是局部变量
编辑: 下面是一个简单的代码片段: YourViewController.h:
@interface YourViewController : UIViewController
@property DeltaViewController *deltaViewController;
@end
YourViewController.m:
@implementation YourViewController
@synthesize deltaViewController;
...
- (void)aMethod;
@end
- (void)dealloc {
self.deltaViewController = nil; // set it to nil & release it after yourViewController dealloced.
[super dealloc];
}
- (void)aMethod {
DeltaViewController *deltaViewController = [[DeltaViewController alloc] initWithNibName:@"DeltaViewController" bundle:nil];
// ...(setup deltaViewController)
self.deltaViewController = deltaViewController; // it'll retain deltaViewController
[deltaViewController release];
...
}
你在仪器中运行僵尸仪器了吗?谢谢,但我不知道怎么做。对不起,我真的是初学者@NickScottman是iVar上的医生。我想你最好先研究一下@NickScottman上面显示了一个简单的代码片段,希望对您有所帮助。好的,我把它放进去了。在
-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
方法中我应该放什么?@NickScottman那是什么?如果您遇到新问题,您需要在SO上创建一个新问题。:)