3

私は2つのテーブルビューを持っています.1つは複数のテーブルビューセルを持ち、各セルは同じサブビューを開きますが、新しいデータで初期化されています..

テーブルには約 100 ~ 200 のエントリがあり、セルが選択されたときにセルをチェックしてからメイン ビューを再びロードするティックであるアクセサリ ビューがあります。

同じデータセットを取得するために同じセルを選択すると、以前に選択したセルが画面の中央に読み込まれます (したがって、そのインデックス パスが認識されます)。 ..

テーブルの上位 30/40% で機能する傾向がありますが、目盛りより低いものは表示されません...つまり、毎回深く深くなって行ったり来たりしない限り、時々目盛りが表示されることがありますテーブルビューのより深い部分で..なぜこれが起こっているのか誰にも分かりますか?

このような性質の何かが以前に起こった人はいますか?

さらに調査すると、このメソッド内で何か問題が発生していると思います..

まず、サブビューでユーザーがセルを選択すると、このメソッドが呼び出されます

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

 // Navigation logic may go here. Create and push another view controller.
    [self.navigationController popViewControllerAnimated:YES]; //pops current view from the navigatoin stack

    //accesses selected cells content
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // now you can use cell.textLabel.text

    //This if statment is based off which cell was selected in the parent view so that it knows which cell to pass the data back to
    if (parentViewSelectedIndexPath.section == 0) {
        if (parentViewSelectedIndexPath.row == 0) {
            manufactureCellTextLabel = cell.textLabel.text; //passing label text over to NSString for use with delegate (check "viewwilldissapear")
            [[self delegate] setManufactureSearchFields:manufactureCellTextLabel withIndexPath:indexPath]; //This is where I pass the value back to the mainview
        }
// a few more If statements for the other methods I can pass data too.


//--- this if block allows only one cell selection at a time
    if (oldCheckedData == nil) { // No selection made yet
        oldCheckedData = indexPath;
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];

    }
    else {
        UITableViewCell *formerSelectedcell = [tableView cellForRowAtIndexPath:oldCheckedData]; // finding the already selected cell
        [formerSelectedcell setAccessoryType:UITableViewCellAccessoryNone];

        [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; // 'select' the new cell
        oldCheckedData = indexPath;
    }   
}

これにより、インデックス パスがメイン ビュー メソッドに渡されます...

   - (void) setManufactureSearchFields:(NSString *)cellLabeltext withIndexPath:(NSIndexPath *)myIndexPath
    {
        manufactureSearchObjectString = cellLabeltext;
        manufactureResultIndexPath = myIndexPath;
        [self.tableView reloadData]; //reloads the tabels so you can see the value.
    }

//次に、サブビューに戻すために次のメソッドで使用される ManufactureResultIndexPath を設定します

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    //--- Idendify selected indexPath (section/row)
    if (indexPath.section == 0) {
        //--- Get the subview ready for use
        VehicleResultViewController *vehicleResultViewController = [[VehicleResultViewController alloc] initWithNibName:@"VehicleResultViewController" bundle:nil];
        // ...
        //--- Sets the back button for the new view that loads
        self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil] autorelease];

        // Pass the selected object to the new view controller.
        [self.navigationController pushViewController:vehicleResultViewController animated:YES];

        [vehicleResultViewController setDelegate:self];

        if (indexPath.row == 0) 
        {
            vehicleResultViewController.title = @"Manufacture";
            [vehicleResultViewController setRequestString:@"ID.xml"]; //sets the request string in searchResultsViewController
            vehicleResultViewController.dataSetToParse = @"ID"; // This is used to controll what data is shown on subview... logic
            [vehicleResultViewController setAccessoryIndexPath:manufactureResultIndexPath]; //sends indexpath back to subview for accessory tick
            vehicleResultViewController.parentViewSelectedIndexPath = indexPath;
        }


//etc etc
}

そして最後に、インデックスパスを oldCheckedData に渡すサブビューのメソッドにそれを渡します

- (void)setAccessoryIndexPath:(NSIndexPath *)myLastIndexPath
{
                oldCheckedData = myLastIndexPath;
                [self.tableView reloadData]; //<<---- this is where I reload the table to show the tick...
}
4

2 に答える 2

2

cell.accessoryType =次のように行をwillDisplayCell:デリゲート関数に移動してみてください。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    // You can move this one here too:
    cell.selectionStyle = UITableViewCellSelectionStyleNone; // no blue selection

    if (indexPath == oldCheckedData) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    } 
}

メソッドは、 /willDisplayCell:のようなセルへの基本的な視覚関連の変更に使用する必要があり、テキストや画像の設定などのセルデータ関連の操作にはメソッドを使用する必要があることを読みました...selectionStyleaccessoryTypecellForRowAtIndexPath:

于 2011-10-14T01:12:13.143 に答える