0

私はCLLocationManagerアプリを持っています。したがって、ユーザーが現在の場所を許可または拒否したかどうかを知る方法が必要です。ユーザーによると、TableController は特定の方法でテーブルに値を追加します。入ろうとしましたが、許可または拒否を選択[sightsTableView reloadData];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocationた後、テーブルビューがリロードされません。Apple の CLLocation リファレンスを調べたところ、役に立つものが見つかりませんでした。UPD:ここにコードサンプルがあります。

 - (void)viewDidLoad {  
      super viewDidLoad];

      [[self locationManager] startUpdatingLocation]; 
      [tempTableView reloadData];
   }
 - (CLLocationManager *)locationManager {

 if (locationManager != nil) {
    return locationManager;
}

        locationManager = [[CLLocationManager alloc] init];
        [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
        [locationManager setDelegate:self];



return locationManager;
}

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

          NSLog(@"User allow get location");
          self.locationError = NO;
          [tempTableView reloadData];

        }



- (void)locationManager:(CLLocationManager *)manager
         didFailWithError:(NSError *)error {
    NSLog(@"User declined get location");
    self.locationError = YES;
    [tempTableView reloadData];


    }

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 .... some big code about a sells )...

    cell.textLabel.text = array.title;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if(self.locationError == NO){
    cell.detailTextLabel.text = @"!";
            }
            return cell;
 }

UPDATE : 実際にはリロードに問題はありません。テーブルビューの更新に問題があることがわかりました。テーブルのスクロールを開始すると、セルに新しい値が表示されます。

2 回目の更新 現在、テーブルが更新されています。問題は、私がどのように電話したかでしUITableViewた。を使用[tempTableView reloadData];しましたが、うまくいかなかったので、これを使用しようとしましたが、[self.tableView reloadData];値をリロードしてリフレッシュしています。

4

2 に答える 2

0
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];

if (!locmanager.locationServicesEnabled)
{
    [contentView setText:@"Location Services Are Not Enabled"];
    return;
}
于 2010-10-02T19:26:48.307 に答える
0

ブレークポイントを設定し、テーブル ビューのデータをリロードするコードが実際に実行されていることを確認しましたか? 実行されていない場合は、View Controller を CLLocationManager のデリゲートとして設定したことを確認してください。

ユーザーが現在地の取得を拒否したかどうかを検出するには、locationManager:didFailWithError: を実装し、エラーのコードが kCLErrorDenied かどうかを確認します。

アップデート

あなたの問題の大部分はこれらの行です

BOOL locationError = NO;
BOOL locationError = YES;

これは、クラスに存在する locationError 変数を設定する代わりに、そのメソッドに存在する新しい変数を作成することです。を削除するBOOLか、self.locationError = NO; を実行します。

于 2010-10-02T20:38:44.730 に答える