Custom Container ViewController Xamarin / Monotouch Example - uiviewcontroller

Does anyone have a simple C# Example showing how you could use Custom Container ViewControllers with Xamarin / Monotouch as per this Apple documentation -
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html

Instead of posting question, thought would be more helpful to go away and create an example.
https://github.com/wickedw/ViewControllerContainer/blob/master/README.md
Readme Excerpt
I got to a point within a project whereby I wanted to display 3 different "Screens" of information based on a user selection.
The TabBarController was not appropriate as the GUI sat within a UINavigationController hierarchy. Yet, the UISegmentedControl fitted the design well.
I already had my views fully coded as seperate ViewControllers (and not all using the same creation pattern, some used Monotouch Dialog, others Nib files, others Programmatic).
Therefore, I did not want to rewrite existing code to use a Single ViewController controlling multiple Views.
I also thought it was time I looked at "Custom ViewController Containers" as they seemed an ideal fit for this scenario.

Related

PrimeFaces with lazy loading and custom filterModes

I have problem figuring out how to incorporate filtering such as this: https://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml
(for example that sales status)
into my lazy loaded datatable based on this: https://www.primefaces.org/showcase/ui/data/datatable/lazy.xhtml
The second example is my base (I only created Car according to the attributes and fixed LazySorter's compare and LazyCarDataModel's load so the applications does not crash and does what it should and it works for me same as the the example on primefaces webpage). So the basic filterBy is functional.
I realize that the filtering with Lazy Load is done in load() function but how to call that load with my custom filter? How to add those filtering methods used in FilterView? They use "PF('carsTable').filter()" in my case carTable but it does nothing. How to somehow connect it with my load function?
(I found several similar but not same problems and solutions or and I tried to decode and use them. I did not manage to make it work so far.)
Additional challenge to solve (if someone would be so great to care :D): Separating those filters into my own buttons not embedded into the datatable (like commandLink or commandButtons).
I'll be grateful for any help. If you need to see my code I can provide it but those examples are basically it and its nicely structured and formated.

How can you present modal UIViewControllers in MonoTouch using MvvmCross?

By adding IMvxModalTouchView to MyView, let the view become modal. But, I cannot change it at runtime. i.e. MyView must be modal every time. Is it possible to make it more flexible, let say, Show(MvxShowViewModelRequest view, bool isModal); ?
This area of MvvmCross is called "preesentation"
Other Mvvm frameworks may refer to it as "INavigationService"
Within MvvmCross, the presenter on each platform is 100% overrideable. Some examples and source code links are provided on http://slodge.blogspot.co.uk/2013/06/presenter-roundup.html
If you want to implement some custom navigation hint, then:
all ShowViewModel calls have an presentationHint parameter - https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxNavigatingObject.cs#L40
the presenters receive these hints in the PresentationValues property of the MvxViewModelRequest in the Show call

MVVMCross Downloadcache - ProgressView during loading

I'm currently testing the downloadcache and this really looks great.
I have some questions regarding this plugin (I'm pretty new to C# and don't understand the full source code of the plugin):
1) ProgressView
I would like to show a progressview on the image until it has been loaded.
To do that, I need to be notified when the image is loaded.
In the "MvxImageViewLoader" I see there is an Action "afterImageChangeAction" (null by default).
However, I don't understand if and how I can access that Action from "MvxImageView"?
(how to set it)
2) Don't load old image
When using Tables or Cellectionviews in iOS, it's important to check if the URL has been changed before setting the image (because iOS reuses the objects). I looked at the source code of the downloadcache and I don't see this check.
However, in the "MvxDynamicImageHelper.cs" class, I see that when a new URL is set, it calls "ClearCurrentHttpImageRequest();" which removes the "update" Events.
So I assume this is enough to prevent that an image is set to the wrong UIImageView?
3) ImageCache size in (mega)bytes
The ImageCache does not have a property to define the mamiximum size (megabytes for example) of the persistent image store (on the HD). I prefer to use a maximum size in (mega)bytes instead of a maximum amount of files because the user will care more how much space an app takes instead of how many files are stored by the app.
I assume the easiest for me is to define a "TimeSpan PeriodSaveInterval" independent from the one in MvxFileDownloadCache to just check the size of the folder defined for the Image Cache or any other recommendations?
Is it dangerous for performance to scan the folder and calculate the size of all the images in a folder?
Regards,
Matt
1) ProgressView
I would like to show a progressview on the image until it has been loaded. To do that, I need to be notified when the image is loaded.
There is a DefaultImagePath which provides the path of an image that should be shown during loading.
But if you need a dynamic animation or other custom view, then afterImageChangeAction can be used
As you've seen, you can't do this in MvxImageView - the Action wasn't really a suitable candidate to be a bindable property so it wasn't exposed as a property.
However, you can:
do this by using MvxImageViewLoader directly in your View - there are several samples of using this in views in the N+1 samples - https://github.com/slodge/NPlus1DaysOfMvvmCross/search?q=MvxImageViewLoader
do this by creating your own MyImageView class - it's not a big class to write - https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxImageView.cs
As an alternative to using the Action callback, you can also inherit from MvxBaseImageViewLoader<T> and provide an override for the ImageHelperOnImageChanged method - see https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding/Views/MvxBaseImageViewLoader.cs#L49
2) Don't load old image
3) ImageCache size in (mega)bytes
The interface-driven and plugin structure of MvvmCross is defined to allow you to implement alternatives.
In the case of loading images from HTTP, there are many alternatives - you don't have to use the MvvmCross download cache for image loading.
The only docs available for the download cache plugin currently is https://github.com/slodge/MvvmCross/wiki/MvvmCross-plugins#downloadcache
For Android, some suggestions for alternative implementations are listed in: https://github.com/slodge/MvvmCross/issues/416
For iOS, it may be useful to read https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html including the section on <Application_Home>/Library/Caches
I know Stuart already provided an excellent answer. But what I did, when I needed the exact same feature, was to subclass MvxImageView and override the UIImageView.Image property. When the image is set I fire an event which is caught by the viewcontroller.

How can I implement composite Views of composite ViewModels?

I'm just getting into my first project with (the unbelieveably excellent) MVVMCross and I can't figure out how to do something that seems fairly basic: composite views.
Suppose I've got a Person (FirstName, LastName, etc), and a person has an Address (Street, City, PostalCode, etc.). So I'll also have a PersonViewModel and an AddressViewModel.
This is a strictly tablet based app (iPad only, actually) and I want to use containment to have the PersonView contain the (reusable) AddressView, such that the outer (person) view binds to Person, while the inner (address) view binds to Person.Address.
I (dimly) understand the presenter concept for showing the views, as discussed here, but I can't see how to handle the propagation of changes from Person to Address and back.
Suppose the Person object has an Address object, but the PersonViewModel shows the AddressViewModel in an AddressView by passing some sort of Address id and rehydrating. Then the AddressView is binding to a different Address object than the one the Person contains. I don't see how to keep the two in sync, which of course would defeat the whole purpose of binding.
How should I do what I'm trying to do?
This is a really wide topic...
...and there are lots of possible answers.
I think it's important to consider ViewModel's as a very simple concept - I'd like to encourage you to think of ViewModels just as being models for views - definitely don't think of them as 'whole page' objects.
....
Within MvvmCross, you can use ShowViewModel and custom presenters to change the UI if you want to - and this is demonstrated in several MvvmCross examples including the split view presenter - http://slodge.blogspot.com/2013/05/n24-splitviewpresenter-n1-days-of.html
This ShowViewModel technique is really useful for navigation - for changing the whole page or for significant portions of it.
However, you don't have to use navigation paradigms if your app doesn't need them.
If you want to, then you can instead:
build your own hierarchies of viewmodels within the core
and you can then build your own databound hierarchies of views within the UIs
It's entirely up to you - your app is king.
....
I feel like I'm not explaining this very well...
....
So I gave up and recorded this video - maybe it helps: http://slodge.blogspot.co.uk/2013/06/n32-truth-about-viewmodels-starring.html
The video and sample code only covers the iPad, but I hope it's easy(ish) to see how you would extend it to other platforms:
for Windows you can use UserControl
for Android you can use MvxFrameControl, custom view or Fragment code.
There's a plugin that allows Control navigation in addition to the default Views navigation, hope it helps: https://github.com/ChristianRuiz/MvvmCross-ControlsNavigation
Please check out this implementation of a custom presenter for MvvmCross projects. To support Fragments in android and also multiple fragments into one other fragment/activity:
https://github.com/JelleDamen/CustomMvxAndroidPresenter

UIViewController workflow management without modal, tabbar and navigationcontroller?

Hello stackoverflow fellows!
Please consider an UI workflow in iOS:
One main viewcontroller and several other viewcontrollers branching out from there:
mainviewcontroller
+-viewcontroller 1
+-viewcontroller 2
+-viewcontroller 3
etc.
I would like to be able to switch and switch back from the main viewcontroller to one of the other viewcontrollers AND also switch BETWEEN the other viewcontrollers.
All iOS patterns I know of seem to be problematic for that usecase:
UITabbarController would be the right choice if I could make the
tabbar disappear - it doesn't fit to the design. I was able to hide
the bar, but the viewcontroller screens don't resize themselves and
the whole thing feels hackish.
UINavigationController is designed for a sequential order of
screens, also the slide-in animation doesn't fit to the design
Modal viewcontrollers are also meant for a sequential order, additionally I have to keep
track of how many viewcontrollers are on the stack. Also, there is a
timing problem with dismissing a view controller and immediately
presenting the next one.
I could just switching views within a viewcontroller I guess, but the
viewcontrollers have all kinds of subtasks to do. I would end up with
one huge viewcontroller and lots of methods embedded for the
different views.
My question:
What would be the best approach to manage a bunch of viewcontrollers in any order I would like to?
Thanks for any help!
I would have a main UIViewController. That one would have references to the other three UIViewControllers. You can then do something like this from inside your main UIViewController:
[self.view addSubview:view1.view];
This works, but I wouldn't advise you doing because it's not the natural way of doing it. As stated by apple:
You should not use view controllers to manage views that fill only a
part of their window—that is, only part of the area defined by the
application content rectangle. If you want to have an interface
composed of several smaller views, embed them all in a single root
view and manage that view with your view controller.
Ok, my solution is not perfect, but seems to work:
Create a UINavigationController.
Use the viewcontrollers: method to add a stack of viewcontrollers to your liking.
When switching between viewcontrollers, rebuild the stack and attach again.
Problem: You only have the navigation controllers animation (slide in/out) at your disposal.
But you can disable the navigationcontrollers animation, get the next viewcontrollers view, animate that in with a UIView animation, then switch to the view controller itself through stack building as explained above.
Really far from perfect, but works.