MKUserTrackingBarButtonItem

MKUserTrackingBarButtonItem

我已经在工具栏中添加了MKUserTrackingBarButtonItem。但是,单击它不会执行任何操作。因此,我假设我需要像普通的UIBarButtonItem一样使用addTarget,但这也不起作用。

如何将方法附加到该按钮,以便可以更改setUserTrackingMode:animated:

MKUserTrackingBarButtonItem *trackingItem = [[[MKUserTrackingBarButtonItem alloc] initWithMapView:mapView] autorelease];
    UISegmentedControl *segmentedControl = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"List", @"Detail", nil]] autorelease];
    segmentedControl.frame = CGRectMake(0, 0, 220, 30);
    [segmentedControl setWidth:100.0 forSegmentAtIndex:0];
    [segmentedControl setWidth:100.0 forSegmentAtIndex:1];
    [segmentedControl setSelectedSegmentIndex:0];
    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    UIBarButtonItem *segmentedButton = [[[UIBarButtonItem alloc] initWithCustomView:segmentedControl] autorelease];
    UIBarButtonItem *pageCurl = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self action:nil] autorelease];
    pageCurl.tintColor = [UIColor lightGrayColor];
    UIBarButtonItem *leftFlex = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
    UIBarButtonItem *rightFlex = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
    self.toolbar.items = [NSArray arrayWithObjects:trackingItem, leftFlex, segmentedButton, rightFlex, pageCurl, nil];

最佳答案

MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:mapView];
[trackButton setTarget:self];
[trackButton setAction:@selector(track:)];

[toolbar setItems:[NSArray arrayWithObjects:trackButton, nil] animated:YES];

关于iphone - MapView:使用MKUserTrackingBarButtonItem切换 map 跟踪状态,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8116811/

10-08 20:53