Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

ios - EXC_BAD_INSTRUCTION at performSelector

I have this code:

dispatch_async(dispatch_get_main_queue(), ^(void) 
{ 
    SEL selector = @selector(callback:);
    [self.delegate performSelector:selector withObject:self];
});

Both self.delegate and self is not nil.

I am getting EXC_BAD_INSTRUCTION at the performSelector line.

Any idea?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try using the selector directly, and make surecallback: is a valid method of self.delegate:

dispatch_async(dispatch_get_main_queue(), ^(void) 
{ 
? ? [self.delegate performSelector:@selector(callback:) withObject:self];
});

Another debugging tip is to set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

See this article for more detailed instructions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...