2014-01-05 21 views
0

我有类似的问题,这里讨论的问题:iOS how to make a button run a code for another view controller? 但它似乎并没有在我的应用程序..我认为我只是犯了一些愚蠢的错误,因为我真的是一个初学者,所以我会很感激任何帮帮我。 因此,我的应用程序(应用程序类似Endomondo,但当然更简单),这是与导航控制器的选项卡应用程序,因为从FirstViewController有连接到MapViewController,它只是一个地图。在FirstViewController有一个按钮 - 开始,我想在按下该按钮移到开始行动myLocation是:iOS如何让一个ViewController中的按钮在许多ViewControllers中启动动作?

-(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]; 

} 

和我FirstViewController IBAction为看起来是这样的:

-(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]; 

} 

,当然行与[mapvc myLocation];是错的。错误是:MapViewController没有可见的@interface声明选择器myLocation。 我宣布:在MapViewController.h-(void)myLocation:(id)sender;FirstViewController.m

回答

0

进口MapViewController.h的错误是:对的MapViewController没有明显的@interface声明 选择myLocation。我已经声明 - (void)myLocation:(id)sender;在 MapViewController.h和 进口MapViewController.h FirstViewController.m

如果是这种情况,调用该方法,你需要使用它代替:

[mapvc myLocation:self]; 

注意,它有一个参数(发件人),你需要通过。

+0

谢谢!错误消失了,但它不显示位置.. – Ola

+0

是的,这是一个完整的蜡母球。我建议您调查一下:http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCsQFjAA&url=http%3A%2F%2Fdeveloper.apple.com%2Flibrary%2Fios %2Fdocumentation%2Fuserexperience%2Fconceptual%2FLocationAwarenessPG%2FCoreLocation%2FCoreLocation.html&EI = PY_JUr3BDMT4oAS-mIDwCw与USG = AFQjCNE8-ncWevcvBbo81w9FeoACd7GKhg与BVM = bv.58187178,d.cGU – valheru

+0

是的,我读过之前,但我认为这个问题是ViewControllers之间传递信息不是myLocation的方法,你认为这有可能吗? – Ola

相关问题