cachvico cachvico - 1 year ago 148
iOS Question

How to add MKUserTrackingBarButtonItem in Interface Builder

Would anyone be able to show me how to add a

to my toolbar in Interface Builder? I have a
on my
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.

Answer Source

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.