I have similar problem to the problem which was discussed here: iOS how to make a button run a code for another view controller? but it didn't seem to be working on my app.. I think I am just making some stupid mistake cause I am really a beginner so I would appreciate any help. So my app (app is something like Endomondo but much simpler of course) which is tabbed bar app with navigation contoller because from FirstViewController there is connection to a MapViewController which is simply a map. In FirstViewController there is a button - Start and I would like that pressing that buttton start action myLocation which is:

-(void)myLocation:(id)sender{
    locationManager = [[CLLocationManager alloc]init];
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    [locationManager startUpdatingLocation];
    [mapview setMapType:MKMapTypeStandard];
    [mapview setZoomEnabled:YES];
    [mapview setScrollEnabled:YES];
    MKCoordinateRegion region = { {0.0, 0.0}, {0.0, 0.0} };
    region.center.latitude = locationManager.location.coordinate.latitude;
    region.center.longitude = locationManager.location.coordinate.longitude;
    region.span.longitudeDelta = 0.007f;
    region.span.latitudeDelta = 0.007f;
    [mapview setRegion:region animated:YES];
    [mapview setDelegate:sender];

}

and my IBAction in FirstViewController looks like this:

 -(IBAction)pressStart{
    [countingSeconds invalidate];
    countingSeconds = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timer) userInfo:nil repeats:YES];
  MapViewController *mapvc = [[MapViewController alloc]init];
    [mapvc myLocation];
    [self.navigationController pushViewController:mapvc animated:YES];

}

and of course the line with [mapvc myLocation]; is wrong. The error is: no visible @interface for MapViewController declares the selector myLocation. I have declared:-(void)myLocation:(id)sender; in MapViewController.h and imported MapViewController.h in FirstViewController.m

有帮助吗?

解决方案

The error is: no visible @interface for MapViewController declares the selector myLocation. I have declared -(void)myLocation:(id)sender; in MapViewController.h and imported MapViewController.h in FirstViewController.m

If this is the case, to call that method, you need to use this instead:

[mapvc myLocation:self];

Note that it has a parameter (sender) that you need to pass.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top