2011-09-28 34 views
0

我工作的家庭作业#3 CS193PFall 2010),图形计算器。我成功实现了委托来传递表达式和比例,现在正在尝试向委托中添加一个额外的字段,如我的earlier question中所引用的。“无法识别选择”错误时访问委托

以下是错误:

>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) 

而这里就是SIGABRT显示了一行:

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

可以在GraphView.m在我Graphing Calculator在GitHub项目中找到。我在iOS 5测试版中使用ARC。

更新

我要补充有在CalculatorBrain类中定义的方法errorForGraphView。我错过了什么(我对代表的理解是前生的),导致每个人都在GraphViewController中查找方法?我应该如何将信息从CalculatorBrain传递给GraphView?

+0

这可能是一个愚蠢的问题......你尝试过实现'errorForGraphView:'方法吗? – darvids0n

+0

是的,你可以在CalculatorBrain.m [链接](https://github.com/mangoldm/Graphing-Calculator/blob/master/Graphing%20Calculator/CalculatorBrain.m) –

+0

但是,这是物体的底部看到它作为委托传递的是一个GraphViewController。奇怪的是,即使GraphViewController采用了GraphViewDelegate协议,它也没有实现该方法。并非GitHub上的所有内容都是无错误的。 –

回答

0

该消息表示正是它说:甲GraphViewController对象被“发送”一个“errorForGraphView:”“消息”(即,“errorForGraphView:”是使用GraphViewController对象指针称为

要么你有错误的指针(也许你应该有一个GraphView对象?),或者你只是忘了实现errorForGraphView :(或者当你实现它时拼错它)

0

那么,如果你看看GraphViewController它没有你指定的方法,所以我建议你看看为什么你将它设置为委托...如果它是正确的事情是委托,然后执行所讨论的方法

1

所以就像他们说的那样,因为没有任何可以定义的方法,但这里确实是一个非常简单的方法来确保方法的定义:) 在任何调用的类中[self.delegate errorForGraphView:self];创建一个协议

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

,然后宣布将委托作为这样

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

,然后合成委托

@sythesize delegate; 

,然后在创建该whateverclassthisis simplye组委托自营类并执行Whatevertheclassis协议并编写该方法:) 当您在实现该协议后键入该方法的头部时,其余的o f函数应该显示出你的意思:)