0

我正在使用QuickDialog他们教程中的常规控制器代码:

QRootElement *root = [[QRootElement alloc] init];
root.title = @"Hello"
root.grouped = YES;

QSection *section = [[QSection alloc] init];
QEntryElement *hello = [[QEntryElement alloc] initWithTitle:@"Hello World" Value:@""];

[root addSection:section];
[info addElement:hello];

UINavigationController *navigation = [QuickDialogController controllerWithNavigationForRoot:root];
[self presentModalViewController:navigation animated:YES];

如何在导航栏中添加“取消”按钮?我试过了:

navigation.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel handler:^(id sender){
    [self.navigationController.modalViewController dismissModalViewControllerAnimated:YES];
}];

......但这没有用。有什么建议么?

4

3 回答 3

0

我在示例逻辑中尝试了您的代码,并通过以下方式实现了取消按钮。

您需要在导航控制器的视图控制器上设置您的 navigationItem 的 leftbarbuttonitem,而不是直接设置到您的导航控制器。

// -- present your root controller.
UINavigationController *navigation = [QuickDialogController controllerWithNavigationForRoot:root];
[self presentModalViewController:navigation animated:YES];
[[[navigation topViewController] navigationItem] setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel handler:^(id sender){
[self.navigationController dismissModalViewControllerAnimated:YES];
}]];
于 2014-07-11T06:42:26.033 回答
0

正确的方法是调整“leftBarButtonItem”的代码,如下所示:

navigation.navigationBar.topItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel handler:^(id sender){
    [self.navigationController.modalViewController dismissModalViewControllerAnimated:YES];
}];
于 2013-11-13T15:54:16.823 回答
0

我知道这已经晚了,但希望这对其他人有帮助。我遇到了类似的问题,并且能够使用以下代码创建一个按钮以从视图中删除表单

navigation.navigationBar.topItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleDone target:self action:@selector(dismissModalViewControllerAnimated:)];
于 2014-03-10T23:29:27.763 回答