添加单元格后 TableViewController 不填充容器
TableViewController doesn't fill container after cells are added
我正在使用 Xamarin iOS,所以这是在 C# 中...
我有一个带有动态单元格的 UITableViewController
-- 一个用于标题和 N 个用户可以添加或删除的单元格。 table 视图下方是带有几个按钮的页脚。触摸添加按钮时,它会导航到新项目的编辑器。当它从编辑器中 returns 时,table 视图突然没有填充它的容器,并且可以看到 parent 视图的背景颜色(UITableView
的背景是Grouped UITableView
样式的默认 ios 灰色。Parent 背景为白色)。
更奇怪的是,这并没有出现在 iOS 模拟器中——仅出现在实际的 iPad.
中
此外,如果再次调用 layoutSubviews()
(例如,将方向更改为纵向),它会自行解决。我们在所有地方都使用相同的容器和通用设计模式,没有任何问题。这是第一个出现问题的视图。
以下是看似相关的代码:
在包含 UITableView
的 parent 视图中:
public override void ViewDidLoad()
{
base.ViewDidLoad();
_propertyView = new BackNotifyingUINavigationController(this); //This navigation controller hosts the table view
AddChildViewController(_propertyView);
_propertyView.View.Frame = PropertyContainer.Bounds;
PropertyContainer.Add(_propertyView.View);
_propertyView.DidMoveToParentViewController(this);
_propertyView.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
//Some unrelated views...
//Some MvvmCross binding stuff...
}
在 table 视图中:
public override void ViewDidLoad()
{
base.ViewDidLoad();
_tableSource = new TableSource(TableView); //Custom MvxTableViewSource. Seemingly not overriding anything relevant
_tableSource.UseAnimations = true;
_tableSource.DeselectAutomatically = true;
_tableSource.ReloadOnAllItemsSourceSets = true;
TableView.AlwaysBounceVertical = false;
TableView.TableHeaderView = new UIView(new CoreGraphics.CGRect(0, 0, TableView.Bounds.Width, 10.0f));
TableView.Source = _tableSource;
TableView.SetEditing(true, false); //Always in editing mode
_doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done);
NavigationItem.RightBarButtonItem = _doneButton;
//Some MvvmCross binding stuff...
}
编辑:这实际上发生在 UINavigationController
上的 Push 或 Pop 上,仅当键盘打开时。
终于找到了一个似乎可以解决问题的解决方法,但感觉就像一个大 hack。
在拥有 UINavigationController 的视图控制器中...
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
if (_propertyView.TopViewController != null)
{
_propertyView.TopViewController.View.Frame = _propertyView.View.Frame;
}
}
当然,这只适用于 ViewController 占用 UINavigationController 的全帧。
似乎应该有更好的方法来处理这个...
我正在使用 Xamarin iOS,所以这是在 C# 中...
我有一个带有动态单元格的 UITableViewController
-- 一个用于标题和 N 个用户可以添加或删除的单元格。 table 视图下方是带有几个按钮的页脚。触摸添加按钮时,它会导航到新项目的编辑器。当它从编辑器中 returns 时,table 视图突然没有填充它的容器,并且可以看到 parent 视图的背景颜色(UITableView
的背景是Grouped UITableView
样式的默认 ios 灰色。Parent 背景为白色)。
更奇怪的是,这并没有出现在 iOS 模拟器中——仅出现在实际的 iPad.
中
此外,如果再次调用 layoutSubviews()
(例如,将方向更改为纵向),它会自行解决。我们在所有地方都使用相同的容器和通用设计模式,没有任何问题。这是第一个出现问题的视图。
以下是看似相关的代码:
在包含 UITableView
的 parent 视图中:
public override void ViewDidLoad()
{
base.ViewDidLoad();
_propertyView = new BackNotifyingUINavigationController(this); //This navigation controller hosts the table view
AddChildViewController(_propertyView);
_propertyView.View.Frame = PropertyContainer.Bounds;
PropertyContainer.Add(_propertyView.View);
_propertyView.DidMoveToParentViewController(this);
_propertyView.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
//Some unrelated views...
//Some MvvmCross binding stuff...
}
在 table 视图中:
public override void ViewDidLoad()
{
base.ViewDidLoad();
_tableSource = new TableSource(TableView); //Custom MvxTableViewSource. Seemingly not overriding anything relevant
_tableSource.UseAnimations = true;
_tableSource.DeselectAutomatically = true;
_tableSource.ReloadOnAllItemsSourceSets = true;
TableView.AlwaysBounceVertical = false;
TableView.TableHeaderView = new UIView(new CoreGraphics.CGRect(0, 0, TableView.Bounds.Width, 10.0f));
TableView.Source = _tableSource;
TableView.SetEditing(true, false); //Always in editing mode
_doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done);
NavigationItem.RightBarButtonItem = _doneButton;
//Some MvvmCross binding stuff...
}
编辑:这实际上发生在 UINavigationController
上的 Push 或 Pop 上,仅当键盘打开时。
终于找到了一个似乎可以解决问题的解决方法,但感觉就像一个大 hack。
在拥有 UINavigationController 的视图控制器中...
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
if (_propertyView.TopViewController != null)
{
_propertyView.TopViewController.View.Frame = _propertyView.View.Frame;
}
}
当然,这只适用于 ViewController 占用 UINavigationController 的全帧。
似乎应该有更好的方法来处理这个...