2014-01-05 18 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

相關問題