2

UITableViewCellヘッダーとフッターだけでなく、カスタムもあります。それらのそれぞれはUITextField、並んでいる列に s を持っています。これらの列の位置は、 の幅に応じてパーセント単位で決定されますUITableView。(つまり、横向きで開いたときに広い画面を利用できます)。

私が抱えている問題は、View Controllerがロードされた後にビューを回転させるときです。はUITableViewCellまだ古いポジショニングを使用しています。

SO を検索したのでdidRotateFromInterfaceOrientation:、このメソッドにデータを実装してリロードしました。

これで、ヘッダーとフッターが並べ替えられました。ただし、 はUITableViewCell回転前の形式のままです。テーブルのすべてのコンテンツを強制的に再描画する方法はありますか?

編集:私のtableView:cellForIndexPath:コード:

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

    static NSString *CellIdentifier = @"CustomCell";
    UITextField *TextField1, *TextField2, *TextField3, *TextField4, *TextField5;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    float width = (self.tableView.frame.size.width - 68);

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

            TextField1 = [[UITextField alloc] initWithFrame:CGRectMake(((width*position1)+10.0), 10.0, (width*width1), 31.0)];
            TextField1.tag = 1;

            TextField2 = [[UITextField alloc] initWithFrame:CGRectMake((width*position2), 10.0, (width*width2), 31.0)];
            TextField2.tag = 2;

            TextField3 = [[UITextField alloc] initWithFrame:CGRectMake((width*position3), 10.0, (width*width3), 31.0)];
            TextField3.tag = 3;

                TextField4 = [[UITextField alloc] initWithFrame:CGRectMake((width*position4), 10.0, (width*width4), 31.0)];
            TextField4.tag = 4;

            TextField5 = [[UITextField alloc] initWithFrame:CGRectMake((width*position5), 10.0, ((width*width5)-40.0-editingWidth), 31.0)];
            TextField5.tag = 5;

            cell.accessoryType = UITableViewCellAccessoryNone;

            [cell.contentView addSubview:TextField1];
            [cell.contentView addSubview:TextField2];
            [cell.contentView addSubview:TextField3];
            [cell.contentView addSubview:TextField4];
            [cell.contentView addSubview:TextField5];

            [TextField1 release];
            [TextField2 release];
            [TextField3 release];
            [TextField4 release];
            [TextField5 release];

        } else {

            TextField1 = (UITextField *)[cell.contentView viewWithTag:1];
            TextField2 = (UITextField *)[cell.contentView viewWithTag:2];
            TextField3 = (UITextField *)[cell.contentView viewWithTag:3];
            TextField4 = (UITextField *)[cell.contentView viewWithTag:4];
            TextField5 = (UITextField *)[cell.contentView viewWithTag:5];

        }

    // Configure the cell...

    // Clear cell contents
    TextField1.text = @"";
    TextField2.text = @"";
    TextField3.text = @"";
    TextField4.text = @"";
    TextField5.text = @"";

    int sectionCount = 0;
    sectionCount = [workoutSectionsMutableArray count];

    // Repopulate cells

    NSMutableArray *cellDataArray = [self retrieveCellDataAtIndexPath:indexPath];

    TextField1.text = [[cellDataArray objectAtIndex:indexPath.row] 1];
    TextField2.text = [[cellDataArray objectAtIndex:indexPath.row] 2];
    TextField3.text = [[cellDataArray objectAtIndex:indexPath.row] 3];
    TextField4.text = [[cellDataArray objectAtIndex:indexPath.row] 4];
    TextField5.text = [[cellDataArray objectAtIndex:indexPath.row] 5];

    }

    return cell;

}

私のdidRotateFromInterfaceOrientation:方法:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation {

    [self.tableView reloadData];
}
4

1 に答える 1

3

テーブルビューでreloadを呼び出すと、データソースでtableView:cellForRowAtIndexPath:メソッドが呼び出されます。セルはすでに初期化されているため、ifステートメント内のコードは呼び出されず、テキストフィールドは再配置されません。

最も簡単な修正は、テキストフィールドコードをifステートメントから移動することです。それが顕著なパフォーマンスヒットを引き起こすかどうかはわかりません。

ちなみに、セルに追加するnameTextField、resistanceTextFieldなどは初期化されていませんが、これはコードからスタックオーバーフローへの転送中に発生した単なる混乱であると思います。追加するのはTextField1、TextField2などであると思います。

于 2012-04-05T20:44:09.263 に答える