异步加载MKMapView?

时间:2010-10-19 14:46:13

标签: iphone mkmapview

当我第一次启动MKMapView时,我的应用似乎在加载时暂停。我假设这是因为它不会异步加载。

有什么方法可以解决这个问题。加载时,您无法切换标签或执行任何操作。

由于

编辑:这是我的viewDidLoad方法:

CGRect bounds = self.view.bounds;
    mapView = [[MKMapView alloc] initWithFrame:bounds];
    mapView.mapType=MKMapTypeStandard;
    mapView.showsUserLocation = YES;
    mapView.delegate = self;

    [self.view insertSubview:mapView atIndex:0];

    NSArray *mapTypes = [NSArray arrayWithObjects:@"Standard",@"Satellite",@"Hybrid",nil];

    mapType = [[UISegmentedControl alloc] initWithItems:mapTypes];
    [mapType setSegmentedControlStyle:UISegmentedControlStyleBar];
    [mapType setCenter:CGPointMake(210, 345)];
    [mapType setSelectedSegmentIndex:0];
    [mapType setTintColor:[UIColor darkGrayColor]];
    [mapType addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:mapType];

    // refresh button...
    UISegmentedControl *refreshButton = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Refresh",nil]] autorelease];
    [refreshButton setSegmentedControlStyle:UISegmentedControlStyleBar];
    [refreshButton setCenter:CGPointMake(self.view.frame.size.width-((refreshButton.frame.size.width/2)+5),(refreshButton.frame.size.height/2)+5)];
    [refreshButton setMomentary:YES];
    [refreshButton setTintColor:[UIColor darkGrayColor]];
    [refreshButton addTarget:self action:@selector(updateMarkers) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:refreshButton];


    UIBarButtonItem *leftBarButton = [[[UIBarButtonItem alloc] initWithTitle:@"List" style:UIBarButtonItemStylePlain target:self action:@selector(goToList)] autorelease];
    [self.navigationItem setRightBarButtonItem:leftBarButton animated:YES];

    // refresh label
    refreshView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, self.view.frame.size.width-74, 40)];
    [refreshView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.8]];
    [refreshView.layer setCornerRadius:5];
    [self.view addSubview:refreshView];

    UILabel *refreshLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5, 5, refreshView.frame.size.width-10, refreshView.frame.size.height-10)] autorelease];
    [refreshLabel setTextColor:[UIColor whiteColor]];
    [refreshLabel setBackgroundColor:[UIColor clearColor]];
    [refreshLabel setFont:[UIFont fontWithName:@"Helvetica" size:12]];
    [refreshLabel setNumberOfLines:2];
    [refreshLabel setLineBreakMode:UILineBreakModeWordWrap];
    [refreshLabel setText:@"Move the map and press 'refresh' to load new results."];
    [refreshView addSubview:refreshLabel];

    [NSTimer scheduledTimerWithTimeInterval:10 target:refreshView selector:@selector(removeFromSuperview) userInfo:nil repeats:NO];

0 个答案:

没有答案