0

나만의 내비게이션 컨트롤러에 자신의 뒤로 버튼, 제목 등으로 덮어 쓰고 싶습니다.하지만 뷰 컨트롤러를 밀어 넣은 후에는 기본적으로 이전 클래스에서 상속 된 스택의 마지막보기의 탐색 막대가 표시됩니다.푸시 된 후 내비게이션 컨트롤러를 무시하는 방법?

내가 헤더 파일에서 NavBarViewController를 상속 한 첫 번째 클래스라고 가정합니다. 내가 다시 뒤로 가기 버튼을 대체 할, 제목을 시도에도 불구하고, 그래서 여전히 ListingDetailViewController와 동일한 네비게이션 컨트롤러에 나타납니다

//ListingDetailViewController.m 
ChatListViewController *chatList= [[ChatListViewController alloc]init]; 
[self.navigationController pushViewController:chatList animated:YES]; 

:

//ListingDetailViewController.h 
@interface ListingDetailViewController : NavBarViewController 

하고, ListingDetailViewController 안에, 내가으로보기를 밀어 ChatListViewController의 viewdidLoad 및 viewWillAppear에 있습니다. ChatListViewController의 헤더입니다.

//ChatListViewController.h 
@interface ChatListViewController : IPChatListViewController 

어떻게하면됩니까? 어떤 도움이라도 대단히 감사합니다. 고맙습니다.

답변

0

viewDidLoad가 상속 된 탐색 모음을 다시 사용할 때까지 viewDidAppear의 단추를 재정 의하여 솔루션을 찾았습니다. 그래서,

-(void)viewDidAppear:(BOOL)animated { 
[self overwriteBackButton]; 
} 
다음

:

- (void)overwriteBackButton { 
UIImage *backNormal = [UIImage imageNamed:@"backButton"]; 
_navBarLeftButton = [OpenSansButton buttonWithType:UIButtonTypeCustom]; 
_navBarLeftButton.frame = CGRectMake(10, 10, 35, 35); 
[_navBarLeftButton setImage:backNormal forState:UIControlStateNormal]; 
[_navBarLeftButton addTarget:self action:@selector(backToList) forControlEvents:UIControlEventTouchUpInside]; 
[self.navigationController.navigationBar addSubview:_navBarLeftButton]; 
} 

그리고이 발생하게됩니다 :

-(void)backToList 
{ 
[self.navigationController popViewControllerAnimated:YES]; 
} 
1

이 목적으로 BaseViewController 클래스를 사용합니다. 베이스 컨트롤러에이 코드를 붙여 넣기 : 당신이 그것을 것이 기본 VC에서보기 컨트롤러 (하지 네비게이션 컨트롤러) 서브 클래스 있는지 확인하는 경우

- (UIBarButtonItem *)createBackButton 
{ 

    UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 
    negativeSeperator.width = 0; 
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigation_back_button.png"] style:UIBarButtonItemStylePlain target:self.navigationController action:@selector(popViewControllerAnimated:)]; 

    [item setTintColor:[UIColor whiteColor]]; 
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSeperator,item, nil]; 
    return item; 
} 

:

if (self.navigationController.viewControllers) 
{ 
    if (self.navigationController.viewControllers.count > 1) 
    { 
     [self createBackButton]; 
    } 
    else 
    { 
     //[self createSideBarButton]; 
    } 
} 
else 
{ 
    //[self createSideBarButton]; 
} 

이 기본 클래스에서이 방법을 포함 자동으로 뒤로 버튼을 대체합니다.

+0

음,이 코드를 작성하는 당신의 노력을 주셔서 대단히 감사합니다. 이 기본 VC에서 내 VC를 서브 클래 싱한다는 것은 무슨 뜻입니까? 왜냐하면, 당신이 체크, 나는 IPChatListViewController ChatListViewController 하위 클래스. 그렇다면이 코드 블록을 어떻게 수정하면 좋을까요? 감사. – Umitk

+0

여전히 ChatListViewController에 이러한 메서드를 넣을 수 있습니다. 내 프로젝트에는 항상 기본 뷰 컨트롤러 클래스가 있습니다. 그 클래스에서 내 모든 뷰 컨트롤러를 서브 클래 싱하려고합니다. 그러나 몇 가지보기 컨트롤러에서 사용할 수 없다면이 코드를 수동으로 추가 할 수 있습니다. –