Gra*_*ten 1 iphone objective-c ios segue
我目前正在使用具有图形功能的计算器应用程序.那么,我在我的计算器中有这个按钮,并将它连接到我的Calculator2ViewController上.此外,我将此按钮连接到另一个名为GraphViewController的UIViewController,并将segue的标识符命名为showGraph.下面是我的segue的代码.
- (GraphViewController *)graphViewController {
return [self.splitViewController.viewControllers lastObject];
}
- (IBAction)graphPressed {
if ([self graphViewController]) {
[[self graphViewController] setProgram:self.brain.program];
}
else {
[self performSegueWithIdentifier:@"showGraph" sender:self];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
[segue.destinationViewController setProgram:self.brain.program];
}
Run Code Online (Sandbox Code Playgroud)
那里,没有错误和警告.但是当我尝试运行应用程序并按下Graph按钮时,应用程序崩溃并在我的控制台上获取此信息.
2012-06-18 11:08:17.272 Calculator2[1135:f803] -[Calculator2ViewController graphPressed:]: unrecognized selector sent to instance 0x6c38850
2012-06-18 11:08:17.273 Calculator2[1135:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Calculator2ViewController graphPressed:]: unrecognized selector sent to instance 0x6c38850'
Run Code Online (Sandbox Code Playgroud)
请告诉我这是为什么会发生这种情况,我怎样才能以更好的方式做到这一点.谢谢!
编辑:
更改- (IBAction)graphPressed到- (IBAction)graphPressed:(id)sender.segue现在有效.但是,我在我的控制台上有这个通知(这有点可怕)
2012-06-18 11:30:02.955 Calculator2[1260:f803] nested push animation can result in corrupted navigation bar
2012-06-18 11:30:03.308 Calculator2[1260:f803] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2012-06-18 11:30:03.309 Calculator2[1260:f803] Unbalanced calls to begin/end appearance transitions for <GraphViewController: 0x6e458d0>.
Run Code Online (Sandbox Code Playgroud)
graphPressed并且graphPressed:是不同的方法.一个有参数参数,另一个没有.您已将其实现为:
-(IBAction)graphPressed
Run Code Online (Sandbox Code Playgroud)
但您可能已将标题中的函数声明为:
-(IBAction)graphPressed:(id)sender
Run Code Online (Sandbox Code Playgroud)
它(理所当然地)视为两个完全独立的功能.现在,你可以实际申报和实施它不带任何参数(-(IBAction)graphPressed)或与参数(-(IBAction)graphPressed:(id)sender),但重要的是,它是在这两个声明和实现一致.声明和实施必须相同.
只是一个提示,最好总是声明IBActions,-(IBAction)myButtonWasPressed:(id)sender因为这可以让你知道按下了什么按钮(通过sender参数),它允许你有多个按钮触发同一事件,但仍然可以告诉哪个是按下.
| 归档时间: |
|
| 查看次数: |
819 次 |
| 最近记录: |