2013-08-02 4 views
0
UIMapViewController *mapViewContr = [[[UIMapViewController alloc] initwithClientKey:clientKey] autorelease]; 
UINavigationController *nc = [[[UINavigationController alloc] initWithRootViewController:mapViewContr] autorelease]; 

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.frame = CGRectMake(0, 0, 44, 44); 
[button setImage:[UIImage imageNamed:@"info2.png"] forState:UIControlStateNormal]; 
UIBarButtonItem *lbutton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease]; 
nc.navigationItem.leftBarButtonItem = lbutton; 

위의 코드는 작동하지 않습니다. leftBarButtonItem은 showBuilderItem을 function으로 설정하면 표시되지 않습니다. UIMapViewController.vieDidLoad, leftBarButtonItem show. 왜? 당신은 항상을 참조 할버튼 항목이 표시되지 않는 이유는 무엇입니까?

mapViewContr.navigationItem.leftBarButtonItem = lbutton; 

:

nc.navigationItem.leftBarButtonItem = lbutton; 

이 될해야합니다 흐르는 코드는 호출 코드의 첫 번째 블록에서 UIMapViewController.vieDidLoad

UIButton *_button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    _button.frame = CGRectMake(0, 0, 44, 44); 
    // [button setBackgroundImage:[UIImage imageNamed:@"info2.png"] forState:UIControlStateNormal]; 
    [_button setImage:[UIImage imageNamed:@"info2.png"] forState:UIControlStateNormal]; 
    UIBarButtonItem *lbutton = [[[UIBarButtonItem alloc] initWithCustomView:_button] autorelease]; 
    self.navigationItem.leftBarButtonItem = lbutton; 

답변

0

navigationItem의 네비게이션 컨트롤러가 아니라보기 컨트롤러입니다.

관련 문제