【发布时间】:2012-08-21 20:19:10
【问题描述】:
当我从一个实现了我试图调用的方法的对象中调用 performSelector:withObject: 时,我得到了一个 EXC_BAD_ACCESS 异常。这是我的代码
SEL newSelector = NSSelectorFromString(@"mySelector:withCustomObject:");
[self performSelector:newSelector withObject:myCustomObject];
这会导致崩溃。但是当我这样做时
[self performSelector:@selector(mySelector:withCustomObject:) withObject:myCustomObject];
它有效。
关于为什么会发生这种情况的任何想法? PS:没有一个参数是nil。
更多代码:
// My code to call this method
SEL newSelector = NSSelectorFromString(@"mySelector:withCustomObject:");
[self performSelector:newSelector withObject:self withObject:myCustomObject];
// this code is NOT called.
- (void) mySelector:(jObject *)sender withCustomObject:(jEvent *)customObject
{
NSDictionary *handlerData = [aProperty objectAtIndex:[event positionInMethodStack]];
NSString *newTitle = [handlerData objectForKey:@"newTitle"];
}
【问题讨论】:
-
崩溃时消息是否说明了什么具体内容?
-
不,我一遍又一遍地点击(调试)继续按钮,它只是在同一个屏幕上显示相同的错误,而不会崩溃并在控制台中记录错误。
-
这很可能是不相关的内存问题:两段代码看起来相同。
标签: iphone objective-c ios exc-bad-access