TableViewController と model class がありTripInfo
ます。セル アクセサリ ビューがタップされたときに、現在の場所のアドレスをセルのテキスト フィールドに返したいと思います。MVCパターンを順守してこれをきれいに行う方法を理解するのに苦労しています。
これが私がこれまでに持っているものです:
1.TableViewController 実装: アクセサリ ビューがタップされ、locationManager
更新が開始されます 2.TableViewController 実装: locationManager
didUpdateLocation メソッドが呼び出され、モデル オブジェクト プロパティに current が設定されますself.tripInfo.location
次に、この場所を物理的な住所に変換する必要があります。このコードを、アドレスを文字列として返すモデル クラス メソッドに入れるつもりでした。次に例を示します。
- (NSString *)createAddressStringFromLocation: (CLLocation *)location
{
__block NSString *locationAddress = @"";
CLGeocoder *gecoder = [[CLGeocoder alloc] init];
[gecoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks lastObject];
locationAddress = [NSString stringWithFormat:@"%@", ABCreateStringWithAddressDictionary(placemark.addressDictionary, NO)];
}];
return locationAddress;
}
次に cellForRow で:
cell.textField.text = [NSString stringWithFormat:@"%@", [self.tripInfo createAddressStringFromLocation:self.tripInfo.fromLocation]];
cellForRow が基本的にこのメソッドがモデルクラスで完了するのを待つのは悪い設計ですか?