UITableView分组 - 如何在旋转后获取单元格contentView的宽度

时间:2011-09-12 07:41:17

标签: objective-c ipad uitableview

在纵向和横向模式之间切换后,表格会调整其宽度。表视图已分组。我需要计算contentView的宽度来改变进度指示器的宽度。 我正在尝试

float contentWidth = [tableView cellForRowAtIndexPath:indexPath].contentView.frame.size.width;

但旋转后的jus会产生一个旧的值,在滚动后会发生变化。

2 个答案:

答案 0 :(得分:1)

试试这个

float contentWidth = [tableView cellForRowAtIndexPath:indexPath].contentView.bounds.size.width;

或者您可以在配置进度指示器时为其设置适当的autoresizingMask

progressIndicator.autoresizingMask = UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

答案 1 :(得分:0)

使用以下方法完成旋转后,您可以重新加载tableView:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

    [self.tableView reloadData];

}

这可以为您提供更新的价值。

相关问题