2017-09-14 4 views
0

私は非常に長いスクリーン(多くのフィールド)を持っています。 Xcodeで構造:XamarinとXCode:UIViewとUITableViewのサイズ変更

View 
    ScrollView 
    View 
     View 
     . 
     . 
     . 
     TableContainer (View) 
     TableView 

TableContainerテーブルビューは高さを持っています。 私がページに行くとき - 私はの高さを設定しましたテーブルビューアイテムの数に応じて高さは、増加するテーブルビューアイテム数によると。 すべて正常です。 しかし、デバイスを回転させると、TableViewが消えます(高さはにリセットされます)。

クラス:

public partial class TrackingView: BaseView<TrackingViewModel> 
    { 
     public TrackingView() : base("TrackingView") 
     { 
     } 

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

      var source = new RetrieveShipmentDetailsViewSource(PortsTable, ShipmentDetailsCell.Key, ShipmentDetailsCell.Key); 
      PortsTable.Source = source; 

      var set = this.CreateBindingSet<TrackingModel, TrackingViewModel>(); 

      set.Bind(ShipmentLabel).To(vm => vm.ShipmentNumber); 
      set.Bind(CustCodeLabel).To(vm => vm.Shipment.CustomerCode); 
      set.Bind(CustNameLabel).To(vm => vm.Shipment.CustomerName); 
     ); 

      ViewModel.ShipmentLoadedSuccess += (sender, e) => 
      { 
       InvokeOnMainThread(delegate 
       { 
        PortsTable.ReloadData(); 
        UpdateView(); 
       }); 
      }; 

      PortsTable.SeparatorStyle = UITableViewCellSeparatorStyle.None; 
      PortsTable.ReloadData(); 

      set.Apply();    
     } 

     private void UpdateView() 
     { 
      if (ViewModel.Shipment != null && ViewModel.Shipment.VesselPorts != null) 
      { 
       PortsTable.ContentSize = new CGSize(MainView.ContentSize.Width, (ViewModel.Shipment.VesselPorts.Count * 200) + 55); 
       PortsTable.Frame = new CGRect(PortsTable.Frame.X, PortsTable.Frame.Y, PortsTable.Frame.Size.Width, 
               (ViewModel.Shipment.VesselPorts.Count * 200) + 55); 
       MainView.ContentSize = new CGSize(MainView.ContentSize.Width, 
                MainView.ContentSize.Height + (ViewModel.Shipment.VesselPorts.Count * 200) + 55); 
      } 
     } 
    } 

私は、iOSでの新たなんだと私は私の構造が良くないことを知っています。 アドバイス、再読み込み方法TableViewおよびScrollView。 助けてください。 Xcodeで

答えて

1

、デバイスを回転させたときに、あなたのUIを更新するには、このAPIを使用します。

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0); 

は、このようなObjective-CのとXcodeでそれを実装します。

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { 

    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 

    // Code here will execute before the rotation begins. 
    // Equivalent to placing it in the deprecated method -[willRotateToInterfaceOrientation:duration:]. 
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
     // Place code here to perform animations during the rotation. 
     // You can pass nil for this closure if not necessary. 
     // Reorganize views, or move child view controllers. 
     if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { 

      //Update UI 
     } 

     if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) { 

      //Update UI 
     } 

    }completion:^(id<UIViewControllerTransitionCoordinatorContext> context){ 
            // Code here will execute after the rotation has finished. 
            // Equivalent to placing it in the deprecated method -[didRotateFromInterfaceOrientation:]. 
            // Do any cleanup, if necessary. 

           }]; 
} 

また、で見つけることができますXamarin.iOS、ViewWillTransitionToSize。そして、C#で以下のように実装することができます:

public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) 
    { 
     base.ViewWillTransitionToSize(toSize, coordinator); 

     coordinator.AnimateAlongsideTransition((IUIViewControllerTransitionCoordinatorContext) => { 

      if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown) 
      { 
       //Update UI 
      } 

      if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft|| UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight) 
      { 
       //Update UI 
      } 

     }, (IUIViewControllerTransitionCoordinatorContext) => { 
      //Transition Completion 
     }); 
    } 
+0

ありがとうございます@ケビン、それは私のために働く! 他の問題を手伝ってください。 1. https://stackoverflow.com/questions/46224467/mvvmcross-hamburger-menu-for-ios 2. https://stackoverflow.com/questions/46202789/mvvmcross-platform-exceptions-mvxexception-could-not-load-plugin-for-t ありがとうございました。 – DaleYY

関連する問題