Reputation: 3289
So as the title said, I'm getting this error in my code. There's no output besides the usual (lldb)
thing. The line it's pointing to is
0x10df051: movl 8(%edx), %edi0x10df051: movl 8(%edx), %edi
The code itself is
DeltaViewController *deltaview = [[DeltaViewController alloc] initWithNibName:@"DeltaViewController" bundle:nil];
It happened when I selected an object in my picker and it should add a subview.
Upvotes: 1
Views: 2585
Reputation: 35131
deltaview
is DeltaViewController type, so it's a controller, not a view. After you've added it as a subview of self.view ([self.view addSubview:deltaview.view];), you might release the deltaview
. Then whenever you sent a method (which is implemented in DeltaViewController) to deltaview
, you'll get this EXC_BAD_ACCESS error of course.
A simple solution: Just declare deltaview
(actually, it should be deltaViewController
instead) as an iVar instead of local variable.
Well, here's a simple code snippet:
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];
...
}
Upvotes: 2