2016-08-12 46 views
1

之後,所以這是在C#...TableViewController不填充容器細胞我使用Xamarin的iOS添加

我有一個UITableViewController動態細胞 - 一個細胞的標題和N多用戶可以添加或刪除。表格視圖下方是一個帶有一對按鈕的頁腳。當添加按鈕被觸摸時,它導航到新項目的編輯器。當它從編輯器返回時,表格視圖突然沒有填充其容器,並且可以看到父視圖的背景顏色(UITableView的背景爲分組UITableView樣式的默認ios灰色,父背景爲白色)。

Screenshot Before navigation

Screenshot After navigation

爲了使它更離奇,這並不在iPhone模擬器顯示 - 只有在實際的iPad。
此外,如果再次調用layoutSubviews()(例如,將方向改爲肖像),它將自行解決。我們在所有地方使用相同的容器和一般設計模式,沒有任何問題。這是第一個顯示問題的視圖。

這裏是代碼看似相關位:

在父視圖包含UITableView

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... 
} 

在表格視圖:

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上,只有當鍵盤打開時。

回答

0

終於找到了一個解決方法,似乎可以做到這一點,但它感覺就像一個大黑客。

在擁有該UINavigationController的視圖控制器...

public override void ViewDidLayoutSubviews() 
    { 
     base.ViewDidLayoutSubviews(); 

     if (_propertyView.TopViewController != null) 
     { 
      _propertyView.TopViewController.View.Frame = _propertyView.View.Frame; 
     } 
    } 

當然,如果你想在視圖控制器擔起的UINavigationController的全畫幅這僅僅是合適的。

似乎應該有更好的方式來處理這個...