Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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 无法通过使用带有自定义视图的UIBarButtonim的代码将分段控件添加到工具栏_Ios_Uinavigationbar_Uibarbuttonitem_Uitoolbar_Uisegmentedcontrol - Fatal编程技术网

Ios 无法通过使用带有自定义视图的UIBarButtonim的代码将分段控件添加到工具栏

Ios 无法通过使用带有自定义视图的UIBarButtonim的代码将分段控件添加到工具栏,ios,uinavigationbar,uibarbuttonitem,uitoolbar,uisegmentedcontrol,Ios,Uinavigationbar,Uibarbuttonitem,Uitoolbar,Uisegmentedcontrol,在我的应用程序中,我曾经在顶部有一个导航栏,底部有一个工具栏,总共有4个按钮。我在工具栏中也有一个分段控件,当切换其他按钮时会显示该控件。使用IBOutlets等,这一切都很好 其中一个按钮是一个粗糙的用户跟踪按钮,我现在用MKUserTrackingButton替换了它。为了实现这一点,我必须通过代码添加它,因为bottomToolBar是UIToolBar的一个IBOutlet: 这很好,但当然称为mapTypeControl的segmentedcontrol现在显示的时间更长了,所以我这样

在我的应用程序中,我曾经在顶部有一个导航栏,底部有一个工具栏,总共有4个按钮。我在工具栏中也有一个分段控件,当切换其他按钮时会显示该控件。使用IBOutlets等,这一切都很好

其中一个按钮是一个粗糙的用户跟踪按钮,我现在用MKUserTrackingButton替换了它。为了实现这一点,我必须通过代码添加它,因为bottomToolBar是UIToolBar的一个IBOutlet:

这很好,但当然称为mapTypeControl的segmentedcontrol现在显示的时间更长了,所以我这样做了:

UIBarButtonItem *segmentControlButton = [[UIBarButtonItem alloc] initWithCustomView:mapTypeControl];
[bottomToolBar setItems:[NSArray arrayWithObjects:trackButton, flexible, segmentControlButton, flexible, keysButton, nil] animated:YES];
但是段控件不显示。如果我将它添加到导航栏中,它会显示出来,但我就是无法让它显示在工具栏中


这里我遗漏了什么?

我需要看更多的代码才能真正理解这里发生了什么,我不清楚为什么要在代码中使用一些按钮,在IB中使用一些按钮。但是,为什么不保留对包含IB中分段控件的UIBarButtonim的引用呢?然后,您不必销毁它并重新创建它,只需将它插入底部工具栏上设置的数组中即可。

是否显示其他按钮?
UIBarButtonItem *segmentControlButton = [[UIBarButtonItem alloc] initWithCustomView:mapTypeControl];
[bottomToolBar setItems:[NSArray arrayWithObjects:trackButton, flexible, segmentControlButton, flexible, keysButton, nil] animated:YES];