MonoTouch.Dialog change DialogViewController style - xamarin.ios

Is this possible to apply new style to already created DialogViewController? In one of my views I need to clear root and change from grouped to plain view.
Just setting style to new one doesn't do anything, so I'm not sure if I need to call some refresh method or this is not possible at all.

Found out looking at Monotouch.Dialog code that you need to call TableView.LoadView for this to happen.

Related

Proper Kentico object for non-user-editable block of static html/javascript

The Situation: I've got a mid-sized chunk of html/javascript that contains an authentication script/input (it's a text input, radio control, and a combo box and a few buttons). What it is is less important than the concept that it's a mass of static client side code that the marketing department can pretty easily accidentally the whole thing.
The Desire: I want the users to be able to add it as a whole to a page, but not be able to modify it. When something needs to change, I want to change it in one place and have it be changed on all the pages.
What I've Tried: Widget with a default text. It works, but feels wrong. Users can edit it, and if they do when I fix it one place it doesn't propagate to all the instances. I'm a bit of a Kentico noob, but it seems like there should be a better way to do this.
Also note: I'm using portal engine if that makes a difference.
A widget is the proper usage. What you make your widget inherit from is the key in this case. I'd suggest creating a new widget based on a static HTML webpart. This way you can set the static HTML markup and hide the property from the content editor on the front end. You can do this by going to the Properties tab of the widget and setting the visibility of the field on the form. Don't delete the field, just hide it. It should be a checkbox that says hide on public form or editing form.
** Edit **
As I read through my answer and comments, I realized I meant to say clone the static HTML webpart and set its default text to your javascript. Then create a widget based on that cloned webpart. The text will reside in the web part and will allow you to update it in one place later, if needed.
I will not do it this way because you will be not able to make changes in the future. You can better create a new webpart this can be an empty webpart and then create a custom layout. In this layout you can put you're code. In this way you can always change you're code in the future and then it will be changed on all the places where the widget is placed.
I'd use a new widget based on the Static HTML webpart (make the field read only or hide it as Brenden mentioned), but store the data in a new custom setting.
no coding needed (only a macro to read the custom setting)
able to edit the script on the fly on any instance in the settings module. If you have multiple of these settings you won't need to go through all kinds of widgets to adjust their default setting but find them on a central place.
Cheers!
David
In this case I think it makes sense to create a custom web part to store all your code in it and use it that way. If you want to achieve it without creating a custom web part, you have to store the code in some non-web part and not widget specific object. I like the suggestion of creating a custom setting. You can then access this custom setting via a macro. This macro can be used as a default property of a newly created web part (inherited e.g. from the static text web part, you'd use the text property). You may as well create a widget out of it. Another approach is to use Kentico localization keys as a workaround. you can create a key in the Localization application and access it again, via a macro, e.g. {?customkey.myhtml?}. The approach with a custom setting however sounds cleaner to me.
This syntax should be working to access a custom setting value via macro:
{%Settings.CustomSettings.xxx%}
{%Settings.CustomSettings["xxx"]%}
{%Settings.CustomSettings.GetValue("xxx")%}

Redraw widgets with update

Let's say I have a button. In it's constructor I use variables to feed the values(before running I set some default values to these variables), so later they can be changed and within the program the look of the GUI can be modified. What I need is to update the widgets whenever I change these values.
For example I have some options to change a certain color, I press the button it calls a certain command defined in the constructor, changes the color variable and after that, it needs to be updated. Here it says the update() redraws widgets as needed. How do I tell it I need the widgets to be redrawn ?
http://effbot.org/tkinterbook/widget.htm
I might be mistaken on what the redrawing actually means. In any case I need it to update with the new values. I have a quite dumb solution for this, that is destroying everything and rebuilding it. I feel like there is a smarter way of doing things.
All widgets have a configure method which can be called to change any of its attributes. All you have to do is keep a reference to the widget(s), and call the method:
def update_the_widgets():
the_label.configure(background="red")
a_button = tk.Button(..., command=update_the_widgets)
the_label = tk.Label(..., background="green")
This is much easier if you use an object oriented style of coding. Otherwise these references need to be global variables.
When your GUI is properly coded you should almost never need to call update.

Wrong View shown (Catel)

I'm trying to open a View with a ViewModel from my MainWindowViewModel.
It works, but all I get is a blank window. It binds the correct title but every other control is missing.
Did anyone have the same problem and found a solution?
You forgot the call to InitializeComponent in your code-behind. Just a tip: create a base class with the Catel behaviors, then use that as a base view. It will keep your actual window code-behind much cleaner.

MonoTouch.Dialog: Dismissing a Keyboard

Using the Reflection API to auto generate a UI.
How can I dismiss the keyboard when the user selects a new field, or if they choose a field which generates a new view to pick from. In the later case, when the user returns to the first screen, the old keyboard is still there.
UIView.EndEditing(bool force);
The above will hide the keyboard for you without needing to know who the first responder is. I haven't done much with the reflection API but you should be able to call that on the view when an element is selected.
Apple Docs -- endEditing:
Clarification for those initially struggling with the MonoDialog portion of the question:
The EndEditing method is not available on DialogViewControllers objects directly (who inherit from UITableViewControllers). You should be calling EndEditing(bool) on the View of a DialogViewController and not trying to call EndEditing(bool) on the actual DialogViewController itself.
For clarification:
DialogViewController dc;
dc.View.EndEditing(true);
Note:
UIView objects include the EndEditing(bool) method, but UITableViewControllers do not inherit from UIView so the EndEditing method is not available on the controller itself. UITableViewControllers contain a view object, call EndEditing on that view object.
Check the ResignFirstResponder method. This one should help you I guess.

MVC basics: Should I add a UIViewController, a Delegate or a Source to my custom view?

my question is about view controllers, delegates and all that in general. I feel perfectly comfortable with UIView, UIViewController, Delegates and Sources, like UITableView does for instance. It all makes sense.
Now I have implemented my first real custom view. No XIBs involved. It is an autocomplete address picker very much like in the Mail application. It creates those blue buttons whenever a recipient is added and has all the keyboard support like the original.
It subclasses UIView. There is no controller, no delegate, no source. I wonder if I should have either one of those? Or all, to make it a clean implementation.
I just cannot put my finger on the sense a view controller would make in my case. My custom view acts much like a control and a UIButton doesn't have a controller either.
What would it control in my view's case?
Some of my thoughts:
For the source: currently the view has a property "PossibleAutocompleteRecipients" which contains the addresses it autocompletes. I guess this would be a candidate for a "source" implementation. But is that really worth it? I would rather pass the controller to the view and put the property into the controller.
The selected recipients can be retrieved using a "SelectedRecipients" property. But views should not store values, I learned. Where would that go? Into the controller?
What about all the properties like "AllowSelectionFromAddressBook"? Again, if I compare with UIButton, these properties are similar to the button's "Secure" property. So they are allowed to be in the view.
The delegate could have methods like "WillAddRecipient", "WillRemoveRecipient" and so on and the user could return TRUE/FALSE to prevent the action from happening. Correct?
Should I maybe inherit from UIControl in the first place and not from UIView?
And last but not least: my custom view rotates perfectly if the device is rotated. Why don't all views? Why do some need a controller which implements ShouldAutoRotateToDeviceOrientation()?
Does it make sense what I wrote above? In the end I will provide the source on my website because it took me some time to implement it and I would like to share it as I have not found a similar implementaion of the Mail-App-like autocomplete control in MonoTouch.
I just want to learn and understand as much as possible and include it in the source.
René
I can answer part of your question.
I just cannot put my finger on the
sense a view controller would make in
my case
The ViewController is responsible for handling the View's state transitions (load, appear, rotate, etc) These transitions are used mainly when you use a navigation component (UINavigationViewController, UITabBarController). These components needs to received a ViewController that will handles the view's transitions.
For exemple, when you push a ViewController on a UINavigationViewController, it will cause the ViewDidLoad, ViewWillAppear, ViewDidAppear. It will also cause the ViewWillDisappear, ViewDidDisappear of the current ViewController.
So, if your application has only one portrait view, you don't need a ViewController. You can add your custom view as a subview of the main window.

Resources