问题
The new Google Analytics SDK introduces a new subclass to UIViewController
from which you have to inherit: GAITrackedViewController
.
More info here: https://developers.google.com/analytics/devguides/collection/ios/v2/screens
This obviously clashes with MvxBindingTouchViewController
, as you can only inherit from one class in C#.
What's the recommended way in getting this working?
回答1:
MvvmCross's MvxTouchViewController's is special...
MvvmCross's MvxBindingTouchViewController is even more special...
But these are only special in that they inherit from standard UIViewControllers (UIVIewController, UITableViewController, UITabBarController, etc) and then they add functionality for:
- ViewModel construction and the ViewModel property at the Cirrious.MvvmCross layer
- construction and storage of Bindings at the Cirrious.MvvmCross.Binding layer
Take a look at some examples:
https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTouchViewController.cs and https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxBindingTouchViewController.cs
https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTouchTableViewController.cs and https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxBindingTouchTableViewController.cs
https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTouchCollectionViewController.cs and https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxBindingTouchCollectionViewController.cs
In these you can hopefully see this involves a fair amount of cut and paste of code - although we do try to minimise it using extension methods. (If C# had multiple inheritance or mixins, we wouldn't need to do that - I'd love to have Mixins... but don't want multiple inhertitance ever!)
So.... if you want to add your own MvxXXXXXBindingViewController, then:
- take your base XXXXX class,
- inherit from it and add 'the stuff' to make an MvxXXXXViewController,
- then take your MvxXXXXXViewController and inherit from it again to make your MvxBindingXXXXXViewController
- publish to your blog and to a new GitHub repo so everyone else can piggyback off your hard work
- job done
Advanced notes:
If you want to see the same thing in Droid, see Insert a Monogame view inside MvvmCross monodroid Activity
The TabBarController is also interesting - it's got some additional methods
At some point 'soon' (first half of this year) we will create VeeThree and this will switch the MvxViewController's to a non generic format - this is because MonoTouch now recommends against using Generics on iOS base classes - Rolf says it's safe most of the time, but when it causes bugs they are 'heisenbugs'.
There is also some dead old-iOS code in the current classes (ViewDidUnload) - this code will be culled in VeeThree too.
来源:https://stackoverflow.com/questions/14518876/integrating-google-mobile-analytics-with-mvvmcross