Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Created August 2, 2013 07:03
Show Gist options
  • Save prashantvc/6138003 to your computer and use it in GitHub Desktop.
Save prashantvc/6138003 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Dialog;
namespace MTDValidation
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
UINavigationController navigation;
RootElement root;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
root = new RootElement ("Validation") {
new Section {
new EntryElement("Company", "Enter company name", " "),
new EntryElement("Title", "Title", " "),
}
};
var dv = new DialogViewController (root);
navigation = new UINavigationController ();
navigation.PushViewController (dv, true);
dv.NavigationItem.RightBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Save, SaveTap);
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
window.RootViewController = navigation;
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
void SaveTap (object sender, EventArgs e)
{
for (int i = 0; i < root.Count; i++) {
var section = root [i];
var entryElements = section.Elements.Where (p => p is EntryElement)
.Select (r => (EntryElement)r);
foreach (EntryElement element in entryElements) {
var cell = element.GetActiveCell ();
var textLabel = cell.TextLabel;
textLabel.TextColor = string.IsNullOrWhiteSpace (element.Value) ? UIColor.Red : UIColor.Black;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment