I have a lot of view controllers that xib is the same. How can I do to associate a Xib to same viewcontrollers in MonoTouch?. I have created a xib only in IB but Xamarin Studio doesn't creates a ".h file".
The simplest and cleanest way is to do a base UIViewController with the nib and inherit from it. This way you follow the DRY principle.
Related
When creating a WatchKit (WatchOS) Interface controller in the storyboard designer/editor, I cannot set it's class to something that is not itself type WKInterfaceController nor an immediate derived child of WKInterfaceController.
Basically in the hope of abstraction and better code reuse, better design overall, I would like to be able to use classes that are how to say, a more distant relative of their base WKInterfaceController
Basically right now it seems that your stuck using the storyboard designer to make a new WatchOS project. And using the storyboard designer you only have the option to select the WKInterfaceController class:
public partial class WKInterfaceController
or one that directly inherits from it:
public partial class ChildInterfaceController : WKInterfaceController
but nothing else such as:
public partial class GrandChildInterfaceController: ChildInterfaceController
So is there any way to do this that doesn't risk the chance of getting corrupted when you reenter the storyboard designer at some point?
Note: I've already asked if it is possible to avoid using a storyboard all together, but that has gone unanswered so I'm assuming no.
For clarity I'm talking about this dialog for "class":
I am following a code only approach for my Xamarin iOS app and can see how you can easily create control such as UILabel and UITextField in ViewDidLoad of a Controller. That is also where I can apply MVVMCross Fluent Binding.
I have seen Stuart's n19 where he creates a custom Circle View and one that creates a Custom Label.
The custom circle overrides the Draw method and draws a circle (Owner Draw)
The custom labels changes the Forecolor of the existing Label (Subclassed)
I don't feel that either of those works for me. I want to create a UIView that is made up of other controls, a composite control. Imagine a control that looked something like this. That would be an ImageView, and 4 labels with one of them clickable.
At what point in the life of the UIView would I create something like that. Is there an equivalent of ViewDidLoad?
As Stuart said in his comment, N=32 - ViewModels and MvxView on the iPad - N+1 days of MvvmCross
is the MVVMCross tutorial you want.
For those that are happy with the idea of ViewModels being more than just a ViewModel per screen and understand Binding the bit around Custom Views starts at minute 20
I am trying to understand how storyboards work in iOS development and how MVVMCross fits in. I thought the best solution would be to build an iOS version of the MVVMCRoss TipCalc Tutorial
I am using Storyboards as you cannot edit XIBs in Visual Studio. My current thinking is one Storyboard per screen.
I have it working but it feels like i did it with more luck than judgement. Therefore I want to check my understanding.
In TipCalc.UI.Touch I have
TipViewController.cs
TipViewController.storyboard
I have added a custom Mvx View Container as suggested in this SO answer. In the CreateViewOfType method of that container I am calling Storyboard.InstantiateViewController and casting that to an IMvxTouchView.
How can a controller be a View as well?
I am planning on having a "View" per storyboard.
If you have multiple views in a storyboard, would you have a controller per view?
When I bring up the Properties window for a "View" in the storyboard designer it has a Name and a class in the Identity section. What is the purpose of the Class property? Does that create a code-behind file?
I am creating the View-to-ViewModel bindings in the ViewDidLoad method of the Controller
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.CreateBinding(this.tipValueText).To<TipViewModel>(vm => vm.Tip).Apply();
this.CreateBinding(this.subTotalTextBox).To<TipViewModel>(vm => vm.SubTotal).Apply();
this.CreateBinding(this.generositySlider).To<TipViewModel>(vm => vm.Generosity).Apply();
}
These bindings work but again I just wanted to check that it is how others do it too.
The iOS ViewController is actually the View in an MVVMCross application. You can think of the view controller as the code behind for the view (so just like a Windows Phone/Windows Store app will have a XAML and related .cs file, or an Android app will have an axml and a java view class)
Yes, when using multiple views in a single storyboard each one will actually be a viewcontroller (since that's what a screen in a storyboard is)
The class property defines which viewcontroller class the layout in the storyboard uses (so which code behind class to use, and if it doesn't exist it will be created)
I prefer a single storyboard as most of my apps don't have too many screens so these are the steps I follow when creating a View in an existing storyboard
Add a ViewController
Type in the view name in the Class field (this name would correspond to the ViewModel name, so HomeView for HomeViewModel, etc.). As soon as you hit enter the ViewController class should be created.
Type in the same view name as the Storyboard Id (this is used to fetch that view)
Add controls and set their names. Setting a control's name will updated the .designer file that was created for the ViewController
Create the ViewDidLoad override in the ViewController class and set up my bindings
If you use a storyboard per view, creating that storyboard with the correct name (HomeView for example) should create the ViewController and designer files for you and give you a storyboard with that one viewcontroller ready to go
edit:
in your bindings, you can use one set.Apply(); at the end
Is there a way to add user defined runtime attributes to a button in Xamarin's storyboard designer?
I'm trying to get Pixate Freestyle to work and need to define the attributes. I can only find the place to define them within xcode.
I was working on a Xamarin Forms project and I figured out that on each platform, there is a method to update the style for a Control. The way I used to do this is something like this:
PixateFreestyle.SetStyleId(view, styleId);
or
PixateFreestyle.SetClassId(view, classId);
Where view is any UIView you want to style ann styleId/classId is a string with the style name in your default.css
Hope this works for you
This is where I based my project
XamarinForms-PixateFreestyle
Getting started with xCode 4.6.3 and I'm running into a hiccup.
I've built a simple app using the UIWebView to display a local HTML file and it's contents. I used that to debug any issues with the HTML and/or image displays and I'm all set.
Now I need to recreate that within a larger project I've built with storyboards for all my navigations between multiple view controllers. My issue comes when I'm trying to control-click drag from the WebView into the ViewController.h code below the #interface like many tutorials show, and that worked fine within my smaller single view controller app. It won't do it. I know I'm missing something obvious here. Am I going to have the set up these screens (I have multiple ones to do this same way) as separate xib files and add them into my main project?
Thanks for any help and clarification.
-Chris
You can create a class called for example myWebViewController and in Interface builder add a UIWebView to it. The control+drag to the header file will work.
Every time you want a UIViewController that has a browser in it, define its class as myWebViewController in Interface Builder.
Try not to repeat code. If you see UIViewControllers or any other UIView...that do the same thing, you can group them into a class that you use over and over.