Would anyone be able to show me how to add a MKUserTrackingBarButtonItem to my toolbar in Interface Builder? I have a UIBarButtonItem on my UIToolbar whose class I have set to MKUserTrackingBarButtonItem, but this doesn’t seem the right way to do it.
I have the following property:
@property (nonatomic, strong) IBOutlet MKUserTrackingBarButtonItem *trackingButton;
And I can add the button in code by using:
trackingButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:mapView];
NSMutableArray *items = [[NSMutableArray alloc] initWithArray:toolbar.items];
[items insertObject:trackingButton atIndex:0];
[toolbar setItems:items];
But I’m just missing how to do it in IB.
Unfortunately this doesn’t seem possible in IB due to the designated initializer of
MKUserTrackingBarButtonItem. You have to instantiate it and add it to the toolbar programmatically, as you are doing.