1

私のアプリでは、coredatabase をフェッチし、結果を self.stores という配列に入れています。これらの店舗の場所を、距離プロパティを持つ MyLocation オブジェクトに変換します。MyLocation オブジェクトを次のようにプロットします。

- (void)plotStorePositions:(NSString *)responseString {

    for (id<MKAnnotation> annotation in _mapView.annotations) {
        [_mapView removeAnnotation:annotation];
    }
    //CYCLE THRU STORE OBJECTS
    for (Store * storeObject in self.stores) {

        NSString * latitude = storeObject.latitude;
        NSString * longitude = storeObject.longitude;
        NSString * storeDescription = storeObject.name;
        NSString * address = storeObject.address;

        //CREATE MYLOCATION OBJECTS
        CLLocationCoordinate2D coordinate;
        coordinate.latitude = latitude.doubleValue;
        coordinate.longitude = longitude.doubleValue;
        MyLocation *annotation = [[MyLocation alloc] initWithName:storeDescription address:address coordinate:coordinate distance:0];

        //CREATE A PIN FOR EACH MYLOCATION ANNOTATION
        CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];

        //SET USERLOCATION (Must move this code out)
        self.userLocation = [[CLLocation alloc] initWithLatitude:self._mapView.userLocation.coordinate.latitude longitude:self._mapView.userLocation.coordinate.longitude];

        //SET USERLOCATION TO APPDELEGATE (Must move this code out)
        AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
        myDelegate.userLocation = self.userLocation;

        //CALCULATE DISTANCE AND SET ITS THAT MYLOCATION's DISTANCE PROPERTY
        CLLocationDistance calculatedDistance = [pinLocation distanceFromLocation:userLocation];
        annotation.distance = calculatedDistance/1000;        

        [_mapView addAnnotation:annotation];

    }

}

これはマップビューにあります。次に、同じコアデータベースをフェッチして self.stores を再度取得するテーブルビューを作成します。次に、その self.stores の配列を循環して STORE storeObjects を作成し、テーブルビュー セルに配置します。しかし、私はそれらのセルをソートしたい。メモリ内にあるはずの MyLocation オブジェクトを取得するにはどうすればよいですか? それらをappDelegateまたはtableviewコントローラーに渡す必要がありますか?

4

1 に答える 1

0

Core Data を使用しているため、最善のオプションは、を使用しNSFetchedResultsControllerてテーブル ビューにデータを入力することです。

必要なのは、別のコントローラーまたはアプリ デリゲートからのマネージド オブジェクト コンテキストだけです。

于 2013-02-14T17:06:48.550 に答える