我结束了以下内容:
在我创建了一个单独的方法,它采用的值的子视图控制器表视图。之后,我设置了首选内容大小。
public void setDocumentList(List<string> documentList){
this.documentList = documentList;
this.TableView.ReloadData();
// adjust size for popover
float height = TableView.ContentSize.Height;
if (this.View.Bounds.Height > 0) {
// limit the max size of the popover
height = Math.Min (this.View.Bounds.Height, height);
}
this.PreferredContentSize = new SizeF (320f, height);
}
在我的容器中我有一个类似的功能,但在这里我只设置了首选的内容大小。
public void setDocumentList(List<string> documentList){
documentListController.setDocumentList (documentList);
this.PreferredContentSize = documentListController.PreferredContentSize;
// some autolayout constraints ...
}
这类作品。我得到正确的值,但popover的值在开始时不正确。如果有人想知道这是C#语言。我仍然乐意提供更好的解决方案。
感谢您的答复。我试过了,但contentSize在孩子中仍然是空的,所以容器得到零值。看起来,在iOS 7中,视图控制器尚未准备好(未计算帧)。在'viewDidAppear'中,我可以查询'contentSize',但这太迟了。 – testing 2014-10-28 11:54:57
您是否尝试使用'layoutSubviews'而不是'layoutIfNeeded'?如果不工作,你可能需要手动计算高度... – jjv360 2014-10-28 12:03:15
现在我'layoutSubviews'试图在'viewDidLoad'我的孩子视图控制器。我仍然得到相同的结果(零值)。我想我会尝试手动计算高度。谢谢! – testing 2014-10-28 12:16:26