简体   繁体   中英

Sending an action to a custom object is crashing the application in ios5.1, xcode 4.3.1

If I try to send an action to a custom object, I get a EXC_BAD_ACCESS. I tested with and without UIStoryboard and with and without ARC. Really strange. The Object seems to be correctly instantiated. -(id)init is called and -(void)awakeFromNib aswell. In the test-xib I added an object and wired it with the custom class. I can wire IBOutlets without any problems. Only actions are crashing. Any ideas?

SimpleObj.m

#import <UIKit/UIKit.h>

@interface SimpleObj : NSObject
-(IBAction)simpleTest:(id)sender;
@end

SimpleObj.h

#import "SimpleObj.h"
@implementation SimpleObj
-(IBAction)simpleTest:(id)sender{
    NSLog(@"Test");
}
@end

Your reference to the custom object is a dangling pointer by the time that the action fires. Top-level objects in a scene are autoreleased, so you must retain them if you'd like to keep 'em around.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM