Permalink
Browse files

[TaksyL10nStoryboard] how to localize storyboard sample

Requires iOS6
  • Loading branch information...
1 parent 0d764b7 commit c18fac7bbb88b39343c8079c3aeaab021dbdff84 @conceptdev committed Jan 2, 2013
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+
+namespace StoryboardTables
+{
+ // 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
+
+ public override UIWindow Window {
+ get;
+ set;
+ }
+
+ //
+ // This method is invoked when the application is about to move from active to inactive state.
+ //
+ // OpenGL applications should use this method to pause.
+ //
+ public override void OnResignActivation (UIApplication application)
+ {
+ }
+
+ // This method should be used to release shared resources and it should store the application state.
+ // If your application supports background exection this method is called instead of WillTerminate
+ // when the user quits.
+ public override void DidEnterBackground (UIApplication application)
+ {
+ }
+
+ // This method is called as part of the transiton from background to active state.
+ public override void WillEnterForeground (UIApplication application)
+ {
+ }
+
+ // This method is called when the application is about to terminate. Save data, if needed.
+ public override void WillTerminate (UIApplication application)
+ {
+ }
+ }
+}
+

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDisplayName</key>
+ <string>TaskyL10n</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.xamarin.samples.taskyl10nstoryboard</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>UIDeviceFamily</key>
+ <array>
+ <integer>1</integer>
+ </array>
+ <key>UIMainStoryboardFile</key>
+ <string>MainStoryboard</string>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ </array>
+</dict>
+</plist>
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+
+namespace StoryboardTables
+{
+ public class Application
+ {
+ // This is the main entry point of the application.
+ static void Main (string[] args)
+ {
+ // if you want to use a different Application Delegate class from "AppDelegate"
+ // you can specify it here.
+ UIApplication.Main (args, null, "AppDelegate");
+ }
+ }
+}
@@ -0,0 +1,3 @@
+"<new task>" = "<new task>";
+"task name" = "task name";
+"other task info"= "other task info";
@@ -0,0 +1,9 @@
+
+"SXg-TT-IwM.placeholder" = "task name";
+"Pqa-aa-ury.placeholder"= "other task info";
+
+"zwR-D9-hM1.text" = "Task Details";
+"bAM-2j-Rzw.text" = "Notes";
+"NF3-h8-xmR.text" = "Done";
+"MWt-Ya-pMf.normalTitle" = "Save";
+"IGr-pR-05L.normalTitle" = "Delete";
@@ -0,0 +1,3 @@
+"<new task>" = "<new task>";
+"task name" = "nombre de la tarea";
+"other task info"= "otra información de tarea";
@@ -0,0 +1,10 @@
+/* MACHINE TRANSLATION : apologies for any mistakes */
+
+"SXg-TT-IwM.placeholder" = "nombre de la tarea";
+"Pqa-aa-ury.placeholder"= "otra información de tarea";
+
+"zwR-D9-hM1.text" = "Detalles de la tarea";
+"bAM-2j-Rzw.text" = "Notas";
+"NF3-h8-xmR.text" = "Completo";
+"MWt-Ya-pMf.normalTitle" = "Guardar";
+"IGr-pR-05L.normalTitle" = "Eliminar";
@@ -0,0 +1,3 @@
+"<new task>" = "<新しいタスク>";
+"task name" = "タスク名";
+"other task info"= "他のタスクの情報";
@@ -0,0 +1,10 @@
+/* MACHINE TRANSLATION : apologies for any mistakes */
+
+"SXg-TT-IwM.placeholder" = "タスク名";
+"Pqa-aa-ury.placeholder"= "他のタスクの情報";
+
+"zwR-D9-hM1.text" = "タスクの詳細";
+"bAM-2j-Rzw.text" = "注釈";
+"NF3-h8-xmR.text" = "削除する";
+"MWt-Ya-pMf.normalTitle" = "はい";
+"IGr-pR-05L.normalTitle" = "削除する";
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+
+namespace StoryboardTables {
+ public class RootTableSource : UITableViewSource {
+ // ##
+ // there is NO database or storage of Tasks in this example, just an in-memory List<>
+ // refer to the other Tasky samples on github for an implementation using SQLite-NET
+ // ##
+ Task[] tableItems;
+ string cellIdentifier = "taskcell";
+
+ public RootTableSource (Task[] items)
+ {
+ tableItems = items;
+ }
+
+ public override int RowsInSection (UITableView tableview, int section)
+ {
+ return tableItems.Length;
+ }
+ public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
+ {
+ // in a Storyboard, Dequeue will ALWAYS return a cell,
+ UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
+ cell.TextLabel.Text = tableItems[indexPath.Row].Name;
+
+ if (tableItems[indexPath.Row].Done)
+ cell.Accessory = UITableViewCellAccessory.Checkmark;
+ else
+ cell.Accessory = UITableViewCellAccessory.None;
+
+ return cell;
+ }
+
+ public Task GetItem(int id) {
+ return tableItems[id];
+ }
+ }
+}
@@ -0,0 +1,142 @@
+using System;
+using System.Drawing;
+using System.Collections.Generic;
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+
+namespace StoryboardTables
+{
+ public partial class RootViewController : UITableViewController
+ {
+ // The list of tasks is NOT persisted, even though you can add and delete tasks
+ // in this sample, the changes are only in memory and will disappear when the app restarts
+ List<Task> tasks;
+
+ public RootViewController (IntPtr handle) : base (handle)
+ {
+ Title = "TaskBoard";
+
+ // Custom initialization
+ tasks = new List<Task> {
+ new Task() {Name="Groceries", Notes="Buy bread, cheese, apples", Done=false},
+ new Task() {Name="Devices", Notes="Buy Nexus, Galaxy, Droid", Done=false}
+ };
+ }
+
+ /// <summary>
+ /// Prepares for segue.
+ /// </summary>
+ /// <remarks>
+ /// The prepareForSegue method is invoked whenever a segue is about to take place.
+ /// The new view controller has been loaded from the storyboard at this point but
+ /// it’s not visible yet, and we can use this opportunity to send data to it.
+ /// </remarks>
+ public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
+ {
+ if (segue.Identifier == "TaskSegue") { // set in Storyboard
+ var navctlr = segue.DestinationViewController as TaskDetailViewController;
+ if (navctlr != null) {
+ var source = TableView.Source as RootTableSource;
+ var rowPath = TableView.IndexPathForSelectedRow;
+ var item = source.GetItem(rowPath.Row);
+ navctlr.SetTask(this, item);
+ }
+ }
+ }
+
+ public void CreateTask () {
+ // first, add the task to the underlying data
+ var newId = tasks[tasks.Count - 1].Id + 1;
+ var newTask = new Task(){Id=newId};
+ tasks.Add (newTask);
+ // then open the detail view to edit it
+ var detail = Storyboard.InstantiateViewController("detail") as TaskDetailViewController;
+ detail.SetTask (this, newTask);
+ NavigationController.PushViewController (detail, true);
+
+ // Could to this instead of the above, but need to create 'new Task()' in PrepareForSegue()
+ //this.PerformSegue ("TaskSegue", this);
+ }
+ public void SaveTask (Task task) {
+ Console.WriteLine("Save "+task.Name);
+ var oldTask = tasks.Find(t => t.Id == task.Id);
+ oldTask = task;
+ NavigationController.PopViewControllerAnimated(true);
+ }
+ public void DeleteTask (Task task) {
+ Console.WriteLine("Delete "+task.Name);
+ var oldTask = tasks.Find(t => t.Id == task.Id);
+ tasks.Remove (oldTask);
+ NavigationController.PopViewControllerAnimated(true);
+ }
+
+
+
+
+
+
+ public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
+ {
+ // Return true for supported orientations
+ return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
+ }
+
+ public override void DidReceiveMemoryWarning ()
+ {
+ // Releases the view if it doesn't have a superview.
+ base.DidReceiveMemoryWarning ();
+
+ // Release any cached data, images, etc that aren't in use.
+ }
+
+ #region View lifecycle
+
+ public override void ViewDidLoad ()
+ {
+ base.ViewDidLoad ();
+
+ // Perform any additional setup after loading the view, typically from a nib.
+ AddButton.Clicked += (sender, e) => {
+ CreateTask ();
+ };
+ }
+
+ public override void ViewDidUnload ()
+ {
+ base.ViewDidUnload ();
+
+ // Clear any references to subviews of the main view in order to
+ // allow the Garbage Collector to collect them sooner.
+ //
+ // e.g. myOutlet.Dispose (); myOutlet = null;
+
+// ReleaseDesignerOutlets ();
+ }
+
+ public override void ViewWillAppear (bool animated)
+ {
+ base.ViewWillAppear (animated);
+
+ // bind every time, to reflect deletion in the Detail view
+ TableView.Source = new RootTableSource(tasks.ToArray ());
+ }
+
+ public override void ViewDidAppear (bool animated)
+ {
+ base.ViewDidAppear (animated);
+ }
+
+ public override void ViewWillDisappear (bool animated)
+ {
+ base.ViewWillDisappear (animated);
+ }
+
+ public override void ViewDidDisappear (bool animated)
+ {
+ base.ViewDidDisappear (animated);
+ }
+
+ #endregion
+ }
+}
+

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,17 @@
+using System;
+
+namespace StoryboardTables {
+ /// <summary>
+ /// Represents a Task.
+ /// </summary>
+ public class Task {
+ public Task ()
+ {
+ }
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string Notes { get; set; }
+ public bool Done { get; set; }
+ }
+}
+
Oops, something went wrong.

0 comments on commit c18fac7

Please sign in to comment.