删除UIImagePickerControler中的取消按钮 - iOS 5.0

时间:2011-12-25 02:15:39

标签: ios cocoa-touch uiimagepickercontroller

我有一个应用程序,它在启动时显示UIImagePickerController。控制器显示取消按钮,但没有要取消的内容。有没有办法删除按钮?

注意:Can the Cancel button be removed from a UIImagePickerController in OS 3.2?的副本。 iOS 3.2的答案在iOS 5中对我不起作用。

2 个答案:

答案 0 :(得分:2)

我尝试将UIImagePickerController设置为非模态,但是采用原始方式(就像我们使用普通的自定义UIViewController一样)。所以,我不需要UINavigationBar中的取消按钮。

没有记录的方法可以删除取消按钮。但here我发现了一些想法。 我刚在AppDelegate.m文件中添加了这段代码:

- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    for (UINavigationItem *item in navigationController.navigationBar.subviews) {
        if ([[item title] compare:@"Cancel"] == 0) {
            UIButton *button = (UIButton *)item;
            [button setHidden:YES];
        }
    }
}

所以现在隐藏了取消按钮。但是,如果您在相册中选择一些文件夹,则下一个视图将使用该按钮(并且不会隐藏)。 然后我尝试添加这样的代码:

- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    for (UINavigationItem *item in navigationController.navigationBar.subviews) {
        if ([[item title] compare:@"Cancel"] == 0) {
            UIButton *button = (UIButton *)item;
            [button setHidden:YES];
        }
    }
}

我在UIImagePickerController导航中的所有导航堆栈中都隐藏了取消按钮。

但是当新视图出现(动画过渡)时,取消按钮也会出现。

我不知道如何解决这个问题。


但是我认为这是一种棘手而低效的方法。因为它可以在将来的iOS更新中破坏您的应用程序。因此,您可以使用that问题的答案。但它完全是不同的方法。

P.S。抱歉我的语言。

答案 1 :(得分:1)

对于iOS 7和8,上述解决方案无效,

由于我们无法使用导航栏中的导航项,因此应该进行少量更改。以下将像魅力一样工作

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    viewController.navigationItem.rightBarButtonItems = nil;
}

- (void)navigationController:(UINavigationController *)navigationController
   didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.navigationItem.rightBarButtonItems = nil;
}
相关问题