2017-09-14 3 views
0

Ich habe einen sehr langen Bildschirm (viele Felder). Struktur in XCode:Xamarin und XCode: Größe ändern UIView und UITableView

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

TableContainer und Tableview haben Höhe . Wenn ich auf der Seite gehe - ich setze Höhe von TableView Höhe nach Artikel zählen und erhöhen TableView nach Artikel zählen. Alles funktioniert OK. Aber wenn ich Gerät drehen - verschwindet TableView (Höhe wird auf zurückgesetzt).

Klasse:

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); 
      } 
     } 
    } 

Ich bin neu in iOS und ich weiß, dass meine Struktur nicht gut ist. Hinweis, bitte, wie neu zu laden TableView und ScrollView. Hilf mir bitte.

Antwort

1

in Xcode Verwenden Sie diese API UI zu aktualisieren, wenn das Gerät drehen:

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

implementieren es in Xcode mit Objective-C wie folgt aus:

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

           }]; 
} 

Es kann auch gefunden werden Xamarin.iOS, ViewWillTransitionToSize. Und es kann mit C# wie folgt implementiert werden:

+0

Danke @Kevin, es funktioniert für mich! Könnten Sie, bitte, helfen Sie mir bei anderen Fragen: 1. https://stackoverflow.com/questions/46224467/mvvmcross-hamburger-menu-for-ios 2. https://stackoverflow.com/questions/46202789/mvvmcross-platform-exceptions-mvxexception-konnte nicht laden-plugin-assembly-for-t Vielen Dank. – DaleYY

Verwandte Themen