I am trying to make table view cell as follows using Xamarin Studio.
public enum Category
{
Travel,
Lodging,
Books
}
I am using Monotouch.Dialog, but cannot find any element.
Any advice?
I guess what you're looking for is the RadioElement of MonoTouch.Dialog. You can see an example in section 3.1 in the MonoTouch.Dialog introduction.
From the example in the doc:
var root = new RootElement ("Meals") {
new Section ("Dinner"){
new RootElement ("Dessert", new RadioGroup ("dessert", 2)) {
new Section () {
new RadioElement ("Ice Cream", "dessert"),
new RadioElement ("Milkshake", "dessert"),
new RadioElement ("Chocolate Cake", "dessert")
}
}
}
}
With this example, you'll have a dialog with one root element called Meals. When tapping this item, you will be presented a new dialog where you can select one of the RadioElements. You create a RadioGroup for the elements that belong together, and the RootElement from which you launch the RadioGroup will show the currently selected value. There's more information about this in section 4.8. of the provided link as well.
Related
I am creating an iPad app using MonoTouch 2.10.11 and I want to MonoTouch.Dialog to create some of the editable fields on a form. One of the fields will use a RadioGroup to allow the user to select from a list of options. The default behavior of M.T.D is display the selection list table over the existing table. This works great for the iPhone layout, but on this iPad form, the table is only on a small area of the form and the navigation bar looks odd on the middle of the form. I want to display the selection as a full screen modal and the user will hit a "back" button to go back the previous form with the selected item.
I created a new RootElement descendant class like this:
public class ModalRootElement : RootElement
{
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
tableView.DeselectRow (path, false);
UIViewController uIViewController = this.MakeViewController ();
this.PrepareDialogViewController (uIViewController);
dvc.PresentViewController (uIViewController, true, null);
}
protected override void PrepareDialogViewController(UIViewController dvc)
{
base.PrepareDialogViewController(dvc);
UIButton button = UIButton.FromType (UIButtonType.RoundedRect);
button.Frame = new RectangleF (5, 5, 80, 20);
button.SetTitle ("back", UIControlState.Normal);
button.TouchUpInside += delegate {
DialogViewController d = dvc as DialogViewController;
(d.Root as ModalRootElement).TableView.ReloadData ();
d.DeactivateController(true);
};
dvc.View.AddSubview (button);
}
}
The table is implemented with the following code:
var _status = new ModalRootElement("Status", new RadioGroup("status", -1)) {
(new Section() {
new RadioElement("New", "status"),
new RadioElement("In process", "status"),
new RadioElement("Rejected", "status"),
new RadioElement("Deferred", "status"),
new RadioElement("Transferred", "status"),
new RadioElement("Unknown", "status"),
new RadioElement("Complete", "status")
})
};
var _odom = new EntryElement ("Odometer", "current odom", "");
_odom.KeyboardType = UIKeyboardType.DecimalPad;
_odom.TextAlignment = UITextAlignment.Right;
var root = new RootElement ("back") {
new Section("") {
_status,
_odom
}
};
_dvc = new DialogViewController(root);
_nav = new UINavigationController (_dvc);
_nav.SetNavigationBarHidden (true, false);
When I run the app, I can drill into the RadioGroup and make a selection. When I click the back button that I added to the view, the modal view closes and the RadioSelected properted of the ModalRootElement object is set correctly, but the text is not displayed.
If I change Selected() method to call dvc.ActivateController instead of PresentViewController, the ModalRootElement displays the correct text, but the RadioGroup table has the wrong size. Is there a way to get the RootElement to display the correct text when you use PresentViewController instead of ActivateController?
I think you need a Root.Reload() call.
Is there a proper way to use Monotouch.Dialog (iOs) and call a UIViewController when a user clicks on a RootElement? I'm building a page of data based on an array and when clicked I'd like to open this custom view and pass in the array element.. Something like this (doesn't work). Any help is appreciated.
RootElement CreateMenuCategory(JToken menucat) {
RootElement MenuCategory = new RootElement(menucat["menucategoryname"].Value<String>());
RootElement root_element;
Section section = new Section();
foreach(JToken menuitem in menucat["menuitems"]) {
root_element = new RootElement(menuitem["menuitemname"].Value<String>(), (RootElement e) => {
return _menuitemView.LoadMenuItem(menuitem); // menuitem on view is always the same
});
section.Add (root_element);
}
MenuCategory.Add (section);
return MenuCategory;
}
That code doesn't work as the delegate always passes in the same element every time.
This is merely a side effect of how the "menuitem" variable is captured by the lambda function.
Change your foreach loop to look like this instead:
foreach (JToken iteratorMenuitem in menucat ["menuitems"]){
var menuitem = iteratorMenuitem;
//.. the rest
I have a RootElement with Sections. One section has RadioElements. How do I change the BackgroundView on the sub section?
Something like this doesn't work because the sub view isn't yet created.:
rootGroups = new RootElement ("Ideas", rdoGroup) {
new RootElement ("Baha'i") {
new Section (){
new RadioElement ("Peace"),
new RadioElement ("Unity"),
new RadioElement ("Science")
}
}
};
???
rootGroups.TableView.BackgroundColor = ...;
If you want to create two different view with two different background you must create another dialogViewController for the second root, that way you will be able to change the background.
To do this, instead of using a regular RootElement constructor, use the RootElement constructor that takes a delegate method that can create the UIViewController on demand.
Hi i m added the File menu item creating the views, my code look like
final Class viewClass : new Class[] { Dashboard.class,
Editor.class, Ticket.class, MockupView.class }) {
navigator.addView(viewClass.getSimpleName(), viewClass);
menu.addItem(viewClass.getSimpleName(), new MenuBar.Command() {
public void menuSelected(MenuItem selectedItem) {
navigator.navigateTo(viewClass);
}
});
but how to add sub menu item inside this menu, any one can help me if you provide me example it will be great full for me
menu.addItem returns a reference to the new menu item, which you can then use to add child items:
MenuBar.MenuItem item = menu.addItem("Parent", null);
item.addItem("Child", null);
Everything you need to know is on this Vaadin documentation page
Are there any existing extensions or is it fairly straight forward to add styles to RootElement in monotouch.dialog in a similar way you can style StyledStringElement.
Basically I would like to add an image, or badge to RootElement to indicate what sort of details would be in the child view, eg add Success, Warning, Error, Info type image - so the users may only be interested in clicking through to details that are not fully successful.
So ideally I would be able to code something like this...
UIImage imageSuccess = ImageLoader.DefaultRequestImage (new Uri ("file://" + Path.GetFullPath ("Images/Success.png")), null);
var root = new RootElement("Root") {
Image = imageSuccess,
Accessory = UITableViewCellAccessory.DetailDisclosureButton,
new Section (){
new BooleanElement ("Airplane Mode", false),
new RootElement ("Notifications") {
new Section (null, "Turn off Notifications")
{
new BooleanElement ("Notifications", false)
}
}}
};
Thanks for any help or pointers.
This question is old, but if anyone else comes across it you can subclass the RootElement class to add an icon. My code is as follows:
public class ImageRootElement : RootElement
{
private UIImage _image;
public override MonoTouch.UIKit.UITableViewCell GetCell (MonoTouch.UIKit.UITableView tv)
{
var baseCell = base.GetCell (tv);
var cell = new UITableViewCell (UITableViewCellStyle.Subtitle, "cellId");
cell.TextLabel.Text = Caption;
cell.Accessory = baseCell.Accessory;
cell.ImageView.Image = _image;
return cell;
}
public ImageRootElement (string caption, UIImage image) : base(caption)
{
_image = image;
}
}
Since MT.Dialog is open source, you can modify the RootElement properties and constructors however you like. I don't think there's anything that does what you want right out of the box, so you'll have to extend Dialog to meet your needs.
As an aside, it sounds like you MAY be misunderstanding the intent of RootElement. RootElement is simply the main container that all of your sections and elements are in. It doesn't seem to make sense to have a disclosure indicator or badge on a RootElement, simply because that is not the intent of RootElement. It's possible that I could just be misunderstanding you. If, however, you want to do custom styling with badges, etc, on an element, you can create custom element classes that inherit from OwnerDrawnElement, overriding it's two abstract methods. However, read Miguel's answer to a similar question here before doing so.