簡體   English   中英

刪除UIImagePickerControler中的取消按鈕-iOS 5.0

[英]Remove Cancel Button in UIImagePickerControler--iOS 5.0

我有一個應用程序,它在啟動時顯示UIImagePickerController。 控制器顯示取消按鈕,但是沒有要取消的內容。 有什么辦法可以刪除按鈕?

注意:這不是一個重復的取消按鈕可以從在的UIImagePickerController OS 3.2去除可以嗎? iOS 3.2的答案不適用於iOS 5。

我嘗試將UIImagePickerController設置為非模態,而是以原始方式(就像我們使用普通的自定義UIViewController一樣)。 因此,我不需要UINavigationBar中的“取消”按鈕。

沒有記錄的方法可以刪除取消按鈕。 但是在這里我發現了一些主意。 我剛剛在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更新中破壞您的應用程序。 所以,你可以使用的答案問題。 但這是完全不同的方法。

PS對不起,我的語言。

對於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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM