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 不显示。但是当我在函数中设置 leftBarButtonItem 时: UIMapViewController.vieDidLoad , leftBarButtonItem 显示。为什么?流动的代码在 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;