0

uitableviewに接続されたカスタムUITableviewCellxibがあり、次のように実行します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil];

    cell = myCell;
    self.myCell = nil;
}

[self configureCell:cell atIndexPath:indexPath];
return cell;
}

次に、デバイスの向きを変更するときに、カスタムUITableViewCellの要素の位置を変更したいので、このメソッドでは次のようにします。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {

    CGRect myframe = CGRectMake(600, self.arrowLabel.frame.origin.y, self.arrowLabel.frame.size.width, self.arrowLabel.frame.size.height);
        self.arrowLabel.frame = myframe;
} else {

    CGRect myframe = CGRectMake(400, self.arrowLabel.frame.origin.y, self.arrowLabel.frame.size.width, self.arrowLabel.frame.size.height);
        self.arrowLabel.frame = myframe;
}
}

UITableViewCell xibに接続されているarrowLabelのframe.origin.yとframe.origin.yを変更しますが、テーブルビューの最後の行の位置のみを変更します。他の行の他のラベルは同じ位置のままなので、質問は、テーブルビューをリロードする方法です。... [self.tableviewreloadData]も試しましたが...動作しません...何か考えはありますか?

4

1 に答える 1

0

フレーム変更コードをに入れてみてくださいcellForRowAtIndexPath。基本的に、その方法では次のようなものがあります。

if (portrait) {
    // use portrait frames
} else {
    // use landscape frames
}

そして、あなたのwillRotateメソッドでを呼び出すことができます[tableView reloadData]

編集:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

for (UITableViewCell *cell in [tableView visibleCells]) {

    if (portrait) {
        CGRect myframe = CGRectMake(600, cell.arrowLabel.frame.origin.y, cell.arrowLabel.frame.size.width, cell.arrowLabel.frame.size.height);
        cell.arrowLabel.frame = myframe;
    } else {
        CGRect myframe = CGRectMake(400, cell.arrowLabel.frame.origin.y, cell.arrowLabel.frame.size.width, cell.arrowLabel.frame.size.height);
        cell.arrowLabel.frame = myframe;
    }
}
}
于 2012-08-02T17:25:55.910 に答える