Ios 为什么按钮不显示?
上面的代码不起作用,LeftBarButtonim不显示。但是当我在函数UIMapViewController.vieDidLoad中设置LeftBarButtonim时,LeftBarButtonim显示。为什么? 流动代码位于UIMapViewController.vieDidLoad中Ios 为什么按钮不显示?,ios,Ios,上面的代码不起作用,LeftBarButtonim不显示。但是当我在函数UIMapViewController.vieDidLoad中设置LeftBarButtonim时,LeftBarButtonim显示。为什么? 流动代码位于UIMapViewController.vieDidLoad中 UIMapViewController *mapViewContr = [[[UIMapViewController alloc] initwithClientKey:clientKey] autorele
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;
在您调用的第一个代码块中:
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;
这应该是:
nc.navigationItem.leftBarButtonItem = lbutton;
您总是希望引用视图控制器的navigationItem
,而不是导航控制器
mapViewContr.navigationItem.leftBarButtonItem = lbutton;