Pergunta

Agora estou desenvolvendo um aplicativo compatível com iOS 4.3 e 5.0.

Meu código funciona bem com o 5.0, mas resulta em um bug complicado no 4.3.

O problema é:

Eu tenho uma visualização com uma tableView nela.Esta visualização possui uma barra de navegação com itens da barra de navegação esquerda e direita.Depois de selecionar a linha na visualização da tabela (e alcançar a visualização correspondente) e retornar, os itens da barra de navegação esquerda e direita "desaparecem".

Já superei essa bagunça nas últimas horas, alguém conseguiu uma cura?

Isso é o que eu já fiz:

Este é o método utilitário que chamo quando o view carrega.

+ (void)setNavigationBarContents:(UIViewController *)view 
{


UIImage *topBarimage=[UIImage imageNamed:NAVIGATION_BAR_IMAGE];


if([view.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {

    [view.navigationController.navigationBar setBackgroundImage:topBarimage forBarMetrics:UIBarMetricsDefault];
}
else 
{
    [view.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:topBarimage] aboveSubview:view.navigationController.navigationBar];

}

UIImage *logo=[UIImage imageNamed:LOGO];
UIImageView *logoView=[[UIImageView alloc]initWithImage:logo];
view.navigationItem.titleView = logoView;

UIImage *settingsButtonImage= [UIImage imageNamed:NAVIGATION_SETTINGS];   
UIButton *rightBarButton = [UIButton buttonWithType: UIButtonTypeCustom];
[rightBarButton setBackgroundImage: settingsButtonImage forState:UIControlStateNormal];  
[rightBarButton addTarget: view action:@selector(settingsButton:) forControlEvents:UIControlEventTouchUpInside];
rightBarButton.frame = CGRectMake(0, 0, 50, 40);  
view.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: rightBarButton];

UIImage *logoutButtonImage= [UIImage imageNamed:LOGOUT];
UIButton *leftBarButton = [UIButton buttonWithType: UIButtonTypeCustom];
[leftBarButton setBackgroundImage: logoutButtonImage forState:UIControlStateNormal];  
[leftBarButton addTarget: view action:@selector(logout:) forControlEvents:UIControlEventTouchUpInside];
leftBarButton.frame = CGRectMake(0, 0, 65, 32);  
view.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: leftBarButton];


}

Tentei chamar isso em viewDidLoad e viewWillAppear, mas em vão.

É assim que chamo isso no viewController.

- (void)viewDidLoad
{

[super viewDidLoad];

//other setups here.

[Utility setNavigationBarContents:self]; 

}
Foi útil?

Solução

Eu encontrei a solução adicionando Este código em meu appDelegate.m

// added so that navigation bar background image works in version lower than 5.0

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed:NAVIGATION_BAR_IMAGE];
[img drawInRect:rect];
}
@end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top