开发者

'Unrecognized Selector' Error When Accessing Delegate

开发者 https://www.devze.com 2023-04-08 16:46 出处:网络
I\'m working on homework assignment #3 fo开发者_StackOverflowr CS193P (Fall 2010), the graphing calculator.I\'ve successfully implemented the delegate to pass the expression and the scale, and am now

I'm working on homework assignment #3 fo开发者_StackOverflowr CS193P (Fall 2010), the graphing calculator. I've successfully implemented the delegate to pass the expression and the scale, and am now trying to add an additional field to the delegate, as referenced in my earlier question.

Here is the error:

>2011-09-27 20:27:24.076 Graphing Calculator[8892:f803] -[GraphViewController errorForGraphView:]: unrecognized selector sent to instance 0x6c32d10

2011-09-27 20:27:24.077 Graphing Calculator[8892:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GraphViewController errorForGraphView:]: unrecognized selector sent to instance 0x6c32d10'

*** First throw call stack:
(0x13bb062 0x154cd0a 0x13bccfd 0x13bd093 0x13220d9 0x1321cf2 0x8876 0x8d83 0x5ca23 0x1d97c13 0x1daa129 0x1cca15d 0x1da9fce 0x1d97ced 0x1d9e27d 0x1d97d13 0x1da1c58 0x1d27fb5 0x1d29ea2 0x1d2957c 0x138f9de 0x1326680 0x12f2516 0x12f1dd4 0x12f1ceb 0x12a4879 0x12a493e 0x1e38b 0x287f 0x27d5 0x1)

terminate called throwing an exceptionCurrent language:  auto; currently objective-c
(gdb) 

And here is the line where the SIGABRT shows up:

BOOL error = [self.delegate errorForGraphView:self];

Which can be found in GraphView.m in my Graphing Calculator project on GitHub. I am using ARC with iOS 5 beta.

Update

I should add that there is an errorForGraphView method defined in the CalculatorBrain class. What am I missing (my understanding of delegates is pre-nascent) that causes everyone to look in GraphViewController to find the method? How should I pass information from CalculatorBrain to GraphView?


So like they said its because there is no method supposedly defined but here is an really really easy way to ensure that the method is defined:) in whatever class that is calling [self.delegate errorForGraphView:self]; create a protocol

@protocol Whatevertheclassis <NSObject>
-(BOOL)errorForGraphView:self];
@end

and then declare your delegate as such

@property(nonatomic, retain) id <Whatevertheclassis> delegate;

and then synthesize the delegate

@sythesize delegate;

and then in the class that creates the whateverclassthisis simplye set delegate to self and implement the Whatevertheclassis protocol and write the method:) As you type the header for the method after implementing the protocol the rest of the function should show up meaning you did it correctly:)


The message means exactly what it say: A GraphViewController object was "sent" an "errorForGraphView:" "message" (ie, "errorForGraphView:" was called using a GraphViewController object pointer.

Either you have the wrong pointer (maybe you should have a GraphView object instead?), or you simply forgot to implement errorForGraphView: (or perhaps spelled it wrong when you implemented it).


Well if you look at GraphViewController it has does not have the method you specified, so i suggest you look into why you are setting it as the delegate...and if its the right thing for it to be the delegate , then implement the method in question

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号