我有類似的問題,這裏討論的問題: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
謝謝!錯誤消失了,但它不顯示位置.. – Ola
是的,這是一個完整的蠟母球。我建議您調查一下: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
是的,我讀過之前,但我認爲這個問題是ViewControllers之間傳遞信息不是myLocation的方法,你認爲這有可能嗎? – Ola