ios - Objective-C: Why do I get an EXC_BAD_ACCESS exception when calling objc_msgSend with a parameter? -
i have got problem while working on own button class in sprite kit / ios 7.0. try call method "objc_msgsend" following error:
thread 1: exc_bad_access (code=1, address=0x8)
here's button class, "identifier" given caller:
// header file *.h @property (nonatomic, readwrite, strong) nsstring* identifier; @property (nonatomic, readonly, weak) id targettouchupinside; @property (nonatomic, readonly) sel actiontouchupinside; // implementation file *.m // ... code in initializer method nsmutablestring *identifier = [[nsmutablestring alloc]init]; [identifier appendformat:@"%d:%d", menuid, itemid]; [self setidentifier:[identifier copy]]; // ... code called inform observer event objc_msgsend(_targettouchupinside, _actiontouchupinside, _identifier);
this callback method called button touch has been detected. point exc_bad_access exception thrown. "identifier" "nil", on ipad air, funnily enough works fine on iphone 4s.
// ... callback method in object instantiates button object - (void)itemtouchinside:(nsstring*)identifier { nslog(@"id called: %@", identifier); }
i observed works on ipad when call "objc_msgsend" ...
- without "_identifier" parameter and/or
- with "int" instead of "nsstring*" parameter
- with predefined immutable nsstring *identifier = @"fixed-string";
but need dynamically define _identifier shown in code snippet above.
any ideas why works on iphone , not on ipad ?
i suggest replace use of objc_msgsend
following:
[self.targettouchupinside performselector:self.actiontouchupinside withobject:self.identifier];
note use of properties too. have properties, use them.
as else mentioned, better define identifier
property copy
instead of strong
. eliminates possible (and difficult find) bugs.
Comments
Post a Comment