2012-05-15 2 views
0

UIImage 및 "뒤로"단추를 내 viewcontroller 나타나는 및 이유를 알아낼 수 없습니다.UIImage 및 "뒤로"단추를 내 viewController에 나타나는

여기 스크린 샷입니다 : 어떤 도움

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    [self.navigationController setNavigationBarHidden:NO animated:YES]; 

    UIImage *image = [UIImage imageNamed:@"arrow_back.png"]; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 

    [self.navigationController.navigationBar addSubview:imageView]; 

} 

감사 :

enter image description here

여기 내 코드입니다.

+0

UIImage를 backButton에 추가 하시겠습니까? – zahreelay

+0

예. 뒤로 버튼이없는 이미지와 그냥 – hanumanDev

답변

2

backbarbutton 항목을 만들고 사용자 정의 항목을 추가해야합니다. 그런 다음 현재보기를 팝하는 위치를 정의합니다.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [button setImage:buttonImage forState:UIControlStateNormal]; 

     //set the frame of the button to the size of the image (see note below) 
     button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height); 

     [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; 

     //create a UIBarButtonItem with the button as a custom view 
     UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 
     self.navigationItem.leftBarButtonItem = customBarItem; 


// selector for backButton 

-(void)back{ 
[self.navigationController popViewController]; 
} 
+0

! - (void) back {} 메서드는 응용 프로그램을 충돌시킵니다. 왜 어떤 생각? 다시 고마워 – hanumanDev

+0

.h 파일에서 다시 메서드를 정의 했습니까? – zahreelay

+0

예. 나는 경고를 받는다 : 인스턴스 메소드 '-popviewcontroller'가 발견되지 않았다. (리턴 타입 디폴트는 ID이다.) – hanumanDev

0

맞춤 검색 버튼을 만들어 self.navigationController.navigationBar.backBarButtonItem의 하위보기로 추가해야합니다.

0

두 번째보기 컨트롤러를 탐색 컨트롤러에 밀어 넣으면 뒤로 단추가 자동으로 나타납니다. Andrew Ebling이 언급 한대로 재정의 할 수 있습니다. 사용자 정의 UIBarButton 항목을 만들어야합니다.

UIImage *image = [UIImage imageNamed:@"back.png"]; 
UIBarButtonItem *back = [UIBarButtonItem alloc] initWithImage:image 
                 style:UIBarButtonItemStylePlain 
                 target:self 
                 action:@selector(backEvent:)]; 

self.navigationItem.backBarButtonItem = back; 
관련 문제