2011-12-04 4 views
1

나는이 것을 의도하고 있습니다 5 탭 항목이있는 탭 막대가 있고 첫 번째 것은 TableViewController에 연결되어 있습니다 tableview 데이터 소스를 결정하고 싶습니다. 사용자의 위치는 도시/국가 처럼 나는 어떻게 사용자 위치를 기반으로 TableViewController 데이터 소스를 변경할 수 있습니까?

locationManager = [[CLLocationManager alloc]init]; 
locationManager.delegate = self; 
locationManager.distanceFilter = KCLDistanceFilterNone; 
locationManager.desiredAccuracy = LCLLocationAccuracyHunderedMeters; 
[locationManager startUpdatingLocation]; 

다음 didUpdateToLocation의 위치를 ​​가져오고 userCurrentLocation 속성에 설정 -ViewDidLoad

이 코드가 있습니다. 그러나 TableView에 대한 데이터 소스를 결정하기 위해 userCurrentLocation을 가져올 수 없습니다. 제발 조언.

는 어디 미리

if (userLocation == @"Sydney") 
{ 
arrData = [NSMutableArray arrayWithObjects:@"San Francisco",nil]; 
} 
else 
{ 
arrData = [NSMutableArray arrayWithObjects:@"California",nil]; 

} 

덕분에 아래처럼 데이터 소스를 설정합니다.

답변

1

당신은이 메소드가 호출 된 후 그래서 난 단지 당신의 tableview로드 시작하는 당신을 추천 할 것입니다 대리자 방법 didUpdateToLocations에 응답해야합니다 :

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 

그런 식으로 당신은 당신이 대답을 얻었다 보장합니다. 자세한 내용은 대표단 documentation을 참조하십시오.

편집 :

먼저 당신이 당신의 클래스의 헤더 파일에 그렇게 할 것 CLLocationManagerDelegate로 클래스를 설정해야합니다.

didUpdateToLocation 대리자 메서드를 호출 할 때 주 컨트롤러에 뷰 컨트롤러를 추가해야하지만 을 viewDidLoad 메서드로 만들어야 할 수도 있습니다.

다른 것이 필요한 경우 알려 주시기 바랍니다.

+0

감사합니다. 하지만 코드 스 니펫의 예를 들어 주시겠습니까?이 방법을 사용하면 현재 테이블보기를로드 할 수 있습니다. 미리 감사드립니다. – developer9

+0

방금 ​​내 글을 편집했습니다. : D –

+0

감사합니다 D. 나는 그것을 시도 할 것이다. 건배 – developer9

관련 문제