1

これが私の問題です。配列の内容に応じて塗りつぶされるテーブルビューがあります。今までは、すべてが順調です。この配列は、サーバーからのマップ名を格納するために使用されます。更新ボタンがあるので、クリックすると、新しいマップ名(refreshメソッド)で配列が更新されます。

更新ボタンをクリックすると、マップ配列が変更されます。一部のマップが追加または削除されます(たとえば、ユーザーがマップを削除したり、新しいマップを作成した場合)。ただし、この状況は画面に反映されません。

5つのマップ(1、2、3、4、5という名前)があるとします。1つを削除して(たとえばマップ3)、refreshを呼び出すと、maps配列(mapsModel->mapsNameList)には4つのマップが含まれ、この配列の内容は適切です。ただし、iPhoneの画面では、テーブルビューに(1,2,4,5,5)が表示されます。マップ配列にない行が削除されない理由はわかりません。

マップ(たとえばマップ0)を追加しようとすると、同じ問題が発生します。(0,1,2,3,4)が得られ、5という数字は表示されません。

アプリケーションを再起動すると、すべてのマップが正しく表示されます...

これが私のコードです。いくつかの変数名が明確でない場合は、私に知らせてください!

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int numberOfRows = [[MapsModel sharedMapsModel] numberOfMapsInSection:((UITabBarController*) self.parentViewController).tabBar.selectedItem.tag];

    // Return the number of rows in the section. THIS FUNCTION WORKS
    return numberOfRows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    MapsModel* mapsModel = [MapsModel sharedMapsModel];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    [[cell textLabel] setText:[[mapsModel->mapsNameList objectAtIndex:((UITabBarController*) self.parentViewController).tabBar.selectedItem.tag] objectAtIndex:indexPath.row]];

    return cell;
}


-(void) refresh {
   [[MapsModel sharedMapsModel] populateMapsNameListWithMapState:MAP_STATE_ALL];

    [self updateView];
}

-(void) updateView {
    //Reorder the maps by alphabetical order
    NSSortDescriptor *sortDescriptor;
    MapsModel* mapsModel = [MapsModel sharedMapsModel];

    sortDescriptor = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];

    NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    [[mapsModel->mapsNameList objectAtIndex:self.tabBarItem.tag] sortUsingDescriptors:sortDescriptors];

    //Update the table view
    [self.tableView reloadData];
}
4

2 に答える 2

0

[[MapsModel sharedMapsModel] numberOfMapsInSection:更新後に正しい値を返しますか?テーブルコードに問題はありません。を確認する必要があるようですMapsModel。おそらくあなたのmapsModelはとに間違った値を返しcellForRowAtIndexPath:ますnumberOfRowsInSection:

于 2013-02-21T07:44:13.790 に答える
0

私は問題を知っています、私はタブバーコントローラーと3つのテーブルビューを持っていました。ただし、3つのテーブルビューすべてに1つのビューコントローラーのみを使用しようとしました...テーブルビューごとに1つのビューコントローラーで問題が解決しました。

于 2013-02-21T08:55:11.267 に答える