iphone - 将后退按钮放在由另一个模态视图插入的模态视图内

标签 iphone objective-c modalviewcontroller

检查一下,我正在将一个模态视图插入另一个模态视图内。但是,我试图在此模态视图中放置一个按钮,但没有运气。

我做错了什么?

谢谢!

 CadastroViewController *addController = [[CadastroViewController alloc] initWithNibName:@"CadastroViewController" bundle:nil];

// This is where you wrap the view up nicely in a navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];

// You can even set the style of stuff before you show it
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(buy)];


// And now you want to present the view in a modal fashion all nice and animated
[self presentModalViewController:navigationController animated:YES];

// make sure you release your stuff
[navigationController release];
[addController release];

最佳答案

您必须将新的 UINavigationItem 添加到实际 View Controller 的导航栏 - 而不是导航 Controller 。

addController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(buy)];

关于iphone - 将后退按钮放在由另一个模态视图插入的模态视图内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4795449/

相关文章:

ios - 无法验证 Facebook publish_actions 权限

iphone - 如何将 iOS 设备键盘更改为特定语言

objective-c - 如何通过键中的子字符串过滤 NSDictionary?

objective-c - PresentModalViewController 与导航 Controller 中的推送 View 具有相同的动画?

objective-c - 在 iOS 5.1 中显示模态视图 Controller 后,UIScrollView 无法正常运行

ios - 除非我禁用自动调整 subview ,否则 UIPickerView 会错误地显示值

iphone - 如何为iPhone开发图像扫描仪(文本识别器)

ios - 错误 | [iOS] 文件模式 : The `source_files` pattern did not match any file

ios - NSDateFormatter dateFromString在iOS 13问题中返回nil

ios - 分派(dispatch)异步代码错误 - Objective C