UitabbarController의 추가 섹션에 나타나는 편집 버튼을 비활성화하는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/825066

  •  05-07-2019
  •  | 
  •  

문제

내 응용 프로그램에서 (탭 막대 응용 프로그램 Xcode 템플릿을 기반으로) UitabbarController를 사용하여 사용자가 액세스 할 수있는 응용 프로그램의 다른 섹션 목록을 표시합니다.

기본적으로 UitabbarController는 5 개 이상의 항목이있을 때 탭 표시 줄에 '더 많은'버튼을 표시합니다. 또한 사용자는 탭 표시 줄에서 볼 수있는 항목을 선택할 수 있습니다.

현재 탭 막대 컨트롤러의 상태를 저장 및로드 할 수 없으므로 '편집'버튼을 비활성화하고 싶습니다.

UitabbarController의 'More'내비게이션 컨트롤러에 나타나는 '편집'막대 버튼을 비활성화/숨길 수있는 방법이 있습니까?

나는 시도했다 :

tabBarController.moreNavigationController.navigationBar.topItem.rightBarButtonItem = nil;

그리고

tabBarController.moreNavigationController.navigationBar.topItem.rightBarButtonItem.enabled = NO;

그러나 그들은 작동하지 않는 것 같습니다.

도움이 되었습니까?

해결책

대의원이 되십시오 moreNavigationController (uinavigationcontroller입니다) 다음을 추가하십시오.

- (void)navigationController:(UINavigationController *)navigationController
        willShowViewController:(UIViewController *)viewController
        animated:(BOOL)animated {

    UINavigationBar *morenavbar = navigationController.navigationBar;
    UINavigationItem *morenavitem = morenavbar.topItem;
    /* We don't need Edit button in More screen. */
    morenavitem.rightBarButtonItem = nil;
}

이제 나타나지 않습니다. 고려해야 할 주요 사항은 컨트롤러 생성 후에 편집 버튼이 나타나지 않고보기를 표시하기 전에 그 순간까지 조용히 앉아서 컨트롤러가 화면을 표시 할 때 버튼을 노크하여 다시 만들 기회는 없습니다. :)

다른 팁

customizableViewControllers 배열입니다. 모든 편집을 비활성화하려면 빈 배열로 설정하십시오.

tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
tabBarController .customizableViewControllers = nil;

나는 시도했고 여기에 예가 있습니다.

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the tab bar controller's view to the window and display.
    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];

    //setting delegate to disable edit button in more.
    tabBarController.moreNavigationController.delegate = self;

    return YES;
}

"편집"버튼을 제거합니다

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        UINavigationBar *morenavbar = navigationController.navigationBar;
        UINavigationItem *morenavitem = morenavbar.topItem;
        /* We don't need Edit button in More screen. */
morenavitem.rightBarButtonItem = nil;
}

당신의 appdelegate.h에서

@interface TestAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate, UINavigationControllerDelegate>

틀 렸으면 고쳐줘.

다음 코드 로이 작업을 수행 할 수있었습니다. 나는 a CustomTabViewController 그런 다음 인터페이스 빌더에서 탭 바 컨트롤러의 클래스 아이덴티티를 수정 하여이 사용자 정의 클래스를 사용했습니다. 다음은 사용하는 코드입니다 (.h 및 .m 파일 내용). 키는 속성을 nil로 설정하는 것입니다. 이로 인해 편집 버튼이 표시되지 않습니다. 자세한 내용은 다음을 참조하십시오. http://developer.apple.com/library/ios/documentation/uikit/reference/uitabbarcontroller_class/reference/reference.html#//apple_ref/occ/instp/uitabbarcontroller/customizableviewcontrollers"어레이가 비어 있거나이 속성의 값이 nil 인 경우 탭 막대는 항목을 재 배열 할 수 없습니다."

#import <UIKit/UIKit.h>

@interface CustomTabBarController : UITabBarController {

}
@end

#import "CustomTabBarController.h"


@implementation CustomTabBarController

- (void)viewDidLoad
{
    self.customizableViewControllers = nil;
    [super viewDidLoad];
}   

@end

이것은 그렇게 달성 될 수 있습니다. 가장 우아한 솔루션은 아니지만 ™가 작동합니다.

// Optional UITabBarControllerDelegate method
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    [self performSelector:@selector(removeEdit) withObject:nil afterDelay:.0001];
}
- (void)removeEdit
{
    tabBarController.moreNavigationController.navigationBar.topItem.rightBarButtonItem = nil;   
}

수명주기 방법에 코드 줄을 추가하기 만하면 IE 응용 프로그램이 시작되었습니다.

- (void)applicationDidFinishLaunching:(UIApplication *)application
{ 
    tabBarController.customizableViewControllers=nil;

}

@m4rkk & @lan terrell 그 코드는 작동하지 않습니다.

나는 그것을 얻을 수 없었기 때문에 내비게이션 막대를 완전히 비활성화합니다.

tabBarController.moreNavigationController.navigationBar.hidden = YES;

iOS4에 대해 잘 모르겠지만 코드를 넣으면 중요합니다. viewDidLoad vs viewWillAppear.

즉, 이것은 작동합니다.

- (void)viewWillAppear:(BOOL)animated
{
self.customizableViewControllers = nil;
}

NavigationController를 1st ViewController로 사용하고 버튼 중 하나를 눌러 UitabbarController를 입력하는 경우. 그런 다음 아래 코드를 추가하는 것 외에도

- (void)navigationController:(UINavigationController *)navigationController
        willShowViewController:(UIViewController *)viewController
        animated:(BOOL)animated 
{
    UINavigationBar *morenavbar = navigationController.navigationBar;
    UINavigationItem *morenavitem = morenavbar.topItem;
    /* We don't need Edit button in More screen. */
    morenavitem.rightBarButtonItem = nil;
}

5 번째 ViewControllers 이상을 처음 클릭하면 편집 버튼이 나타나지 않도록이 "if 문"을 추가해야합니다.

if (self.selectedIndex >= 4) 
{
    self.customizableViewControllers = nil;
}

4.0보다 큰 Xcode에서 작업하는 사람들 (스노우 레오파드의 경우 Xcode 4.2에서 작업하고 있습니다) :

처음에는 마지막으로 뷰 배열을 어디에서 변경합니까? 사용자 정의 가능한 View-Array를 NIL로 설정하는 방법이 중요하지 않다고 생각합니다. 사과 설명은 다음과 같습니다.

중요 : 탭 바 인터페이스에서 뷰 컨트롤러 추가 또는 제거 또는 사용자 정의 가능한 뷰 컨트롤러 배열을 기본 값으로 재설정하여 모든 뷰 컨트롤러를 다시 사용자 정의 할 수 있습니다. 따라서 ViewControllers 속성 (setViewControllers : Animated : Method)을 직접 또는 직접 호출하여 수정하고 사용자 정의 가능한 뷰 컨트롤러를 제한하려면 사용자 정의 가능한 ViewControllers 속성에서 객체 배열을 업데이트해야합니다.

그것은 나를 위해 일 했으므로 시도해보십시오. 이 설명을 여기에서 찾았습니다. Developer.apple.com의 설명에 대한 링크 장에서 "탭의 사용자 정의 방지"에서.

iPhone 6 Plus는 탭 막대에서 조경 모드에서 인물 사진보다 더 많은 버튼을 허용합니다. 불행히도 이것은 장치가 회전 할 때마다 사용자 정의 가능한 ViewControllers 어레이를 재설정하고 여기에서 답이 없었습니다.

나는 이미 내 자신의 UitabbarController 서브 클래스를 가지고 있었고 사용자 정의 가능한 ViewControllers를위한 세터와 getter 메소드를 재정의했습니다. 더 많은 화면에서 편집 버튼을 제거하는 유일한 안정적인 방법이었습니다.

- (NSArray *)customizableViewControllers
{
    return nil;
}

- (void)setCustomizableViewControllers:(NSArray*)controllers
{
    //do nothing
}

이것은 늦은 추가이지만 도움이되는 기여라고 생각합니다. Aleks N의 답변은 Rightbarbuttonitem Bao Lei가 언급 한 것처럼 "더 많은 탭"아래의 모든 뷰 컨트롤러에 대해 제거됩니다. Bao Lei의 코드를 사용하는 것이 좋습니다. DidShowViewController 대표 방법.

현재 코드가 존재하므로 사용자는 "더 많은"탭을 활용하여 기본으로 돌아갑니다. uimoreviewcontroller 테이블이 유발할 수 있습니다 Rightbarbuttonitem 다른 ViewControllers에 속하는 것은 nil로 설정됩니다.

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if (navigationController.viewControllers.count == 1)
    {
        UINavigationBar *morenavbar = navigationController.navigationBar;
        UINavigationItem *morenavitem = morenavbar.topItem;
        /* We don't need Edit button in More screen. */
        morenavitem.rightBarButtonItem = nil;
    }
}

구별은 작지만이 버그를 찾는 데 상당한 시간이 걸렸습니다.

Aleks N의 답변은 작동하지만 조금 수정하고 싶습니다.

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if (navigationController.viewControllers.count == 1)
    {
        UINavigationBar *morenavbar = navigationController.navigationBar;
        UINavigationItem *morenavitem = morenavbar.topItem;
        /* We don't need Edit button in More screen. */
        morenavitem.rightBarButtonItem = nil;
    }
}

이 뷰 컨트롤러 가이 뷰 스택에서 푸시되거나 튀어 나올 때 마다이 대의원 메소드가 호출되므로. 우리 가이 "더 많은"보기 컨트롤러에 대한 다른 뷰를 푸시 할 때, 우리는 이것을하고 싶지 않습니다.

나를 위해 일한 유일한 해결책

self.moreNavigationController.navigationBar.topItem?.rightBarButtonItem?.title = ""
self.moreNavigationController.navigationBar.topItem?.rightBarButtonItem?.isEnabled = false

이러한 솔루션의 대부분을 시도했는데 장치를 회전 할 때 편집 버튼이 돌아올 문제가 발생했습니다. 회전은 첫 번째보기 컨트롤러로 다시 재설정 한 다음 More View 컨트롤러로 돌아 왔을 때 편집 버튼이있었습니다. 가장 좋은 해결책은 UITabBarControllerDelegate 더 많은보기 컨트롤러가 선택된보기 컨트롤러가 될 때마다 오른쪽 막대 버튼을 nil로 설정하십시오. 이것은 iOS 11-12에서 작동합니다.

final class DashboardController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        delegate = self
    }
}

extension DashboardController: UITabBarControllerDelegate {
    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        if viewController == moreNavigationController {
            moreNavigationController.navigationBar.topItem?.rightBarButtonItem = nil
        }
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top