Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么按钮不显示?_Ios - Fatal编程技术网

Ios 为什么按钮不显示?

Ios 为什么按钮不显示?,ios,Ios,上面的代码不起作用,LeftBarButtonim不显示。但是当我在函数UIMapViewController.vieDidLoad中设置LeftBarButtonim时,LeftBarButtonim显示。为什么? 流动代码位于UIMapViewController.vieDidLoad中 UIMapViewController *mapViewContr = [[[UIMapViewController alloc] initwithClientKey:clientKey] autorele

上面的代码不起作用,LeftBarButtonim不显示。但是当我在函数UIMapViewController.vieDidLoad中设置LeftBarButtonim时,LeftBarButtonim显示。为什么? 流动代码位于UIMapViewController.vieDidLoad中

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;