ModalViewController 使用选择器关闭视图
我有一个从主视图中呈现的模态视图控制器,我在视图的右上角添加了一个“完成”按钮(导航控制器)。但是,我无法让选择器调用正确的方法。这是我用来设置模式视图的代码:
GraphView *graphView = [[[GraphView alloc] initWithNibName:@"GraphView" bundle:nil] autorelease];
//Set values in the graphView view
[graphView setInterest:interestRateSlider.value / 10];
[graphView setMonths: (loanTermSlider.value / 2.0) * 12]; // Years * 12 = months
[graphView setPrincipal:[principal intValue]];
//show the graph view as a modal navigation controller view
UINavigationController *graphNavigationController = [[UINavigationController alloc] initWithRootViewController:graphView];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:graphView
action:@selector(dismissView:)];
graphView.navigationItem.rightBarButtonItem = doneButton;
[graphNavigationController.navigationItem.rightBarButtonItem setTitle:@"Done"];
[graphView.navigationItem setTitle:@"Graph"];
[self presentModalViewController:graphNavigationController animated:YES];
[graphNavigationController release];
[doneButton release];
然后在我的 graphView 类中,我有方法:
-(void) dismissView {
[self dismissModalViewControllerAnimated: YES];
}
但是,在运行代码时,我得到无法识别的选择器。选择器尝试调用 UINavigationController 变量上的方法。如何让选择器调用正确的方法?
谢谢
I have a modal view controller that is presented from my main view, I am adding a "Done" button in the top right hand side of the view (navigationcontroller). However, I can't get the selector to call the right method. Here is the code I am using to set up the modal view:
GraphView *graphView = [[[GraphView alloc] initWithNibName:@"GraphView" bundle:nil] autorelease];
//Set values in the graphView view
[graphView setInterest:interestRateSlider.value / 10];
[graphView setMonths: (loanTermSlider.value / 2.0) * 12]; // Years * 12 = months
[graphView setPrincipal:[principal intValue]];
//show the graph view as a modal navigation controller view
UINavigationController *graphNavigationController = [[UINavigationController alloc] initWithRootViewController:graphView];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:graphView
action:@selector(dismissView:)];
graphView.navigationItem.rightBarButtonItem = doneButton;
[graphNavigationController.navigationItem.rightBarButtonItem setTitle:@"Done"];
[graphView.navigationItem setTitle:@"Graph"];
[self presentModalViewController:graphNavigationController animated:YES];
[graphNavigationController release];
[doneButton release];
Then in my graphView class I have the method:
-(void) dismissView {
[self dismissModalViewControllerAnimated: YES];
}
However, when running the code I get unrecognized selector. The selector is trying to call the method on the UINavigationController variable. How can I get the selector to call the right method?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用选择器时犯了一个错误:
当您定义missView时,
您应该将dismissView定义为
或不带冒号调用它
You made a mistaken when calling the selector:
when dismissView is defined as
you should define dismissView as
or call it without colon