public override void ViewDidLoad () { base.ViewDidLoad (); Title = "Fonts"; // declare vars NavItemGroup navGroup; string fontName; UIFont font; NavItem navItem; Type controller; for (int i = 0; i < UIFont.FamilyNames.Length; i++) { // create a nav group navGroup = new NavItemGroup (UIFont.FamilyNames[i]); navItems.Add (navGroup); // loop through each font name in the family for (int j = 0; j < UIFont.FontNamesForFamilyName (UIFont.FamilyNames[i]).Length; j++) { // add an item of that font fontName = UIFont.FontNamesForFamilyName (UIFont.FamilyNames[i])[j]; font = UIFont.FromName (fontName, UIFont.SystemFontSize); if((UIApplication.SharedApplication.Delegate as AppDelegate).CurrentDevice == DeviceType.iPad) { controller = typeof(Screens.iPad.FontViewer.FontViewerScreen_iPad); } else { controller = typeof(Screens.iPhone.FontViewer.FontViewerScreen_iPhone); } navItem = new NavItem (fontName, "", controller, new object[] { font }); navItem.Font = font; navGroup.Items.Add (navItem); } } // create a table source from our nav items tableSource = new NavItemTableSource (NavigationController, navItems); // set the source on the table to our data source base.TableView.Source = tableSource; }
/// <summary> /// Called by the TableView to actually build each cell. /// </summary> public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { NavItem navItem = this.navItems[indexPath.Section].Items[indexPath.Row]; var cell = tableView.DequeueReusableCell(this.cellIdentifier); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Default, this.cellIdentifier); cell.Tag = Environment.TickCount; } //---- set the cell properties cell.TextLabel.Text = this.navItems[indexPath.Section].Items[indexPath.Row].Name; cell.Accessory = UITableViewCellAccessory.DisclosureIndicator; if (navItem.Font != null) { cell.TextLabel.Font = navItem.Font; } return(cell); }
/// <summary> /// Is called when a row is selected /// </summary> public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { //---- get a reference to the nav item NavItem navItem = navItems[indexPath.Section].Items[indexPath.Row]; // if the nav item has a proper controller, push it on to the NavigationController // NOTE: we could also raise an event here, to loosely couple this, but isn't neccessary, // because we'll only ever use this this way if (navItem.Controller != null) { navigationController.PushViewController(navItem.Controller, true); // show the nav bar (we don't show it on the home page) navigationController.NavigationBarHidden = false; } else { if (navItem.ControllerType != null) { ConstructorInfo ctor = null; // if the nav item has constructor aguments if (navItem.ControllerConstructorArgs.Length > 0) { // look for the constructor ctor = navItem.ControllerType.GetConstructor(navItem.ControllerConstructorTypes); } else { // search for the default constructor ctor = navItem.ControllerType.GetConstructor(System.Type.EmptyTypes); } // if we found the constructor if (ctor != null) { UIViewController instance = null; if (navItem.ControllerConstructorArgs.Length > 0) { // instance the view controller instance = ctor.Invoke(navItem.ControllerConstructorArgs) as UIViewController; } else { // instance the view controller instance = ctor.Invoke(null) as UIViewController; } if (instance != null) { // save the object navItem.Controller = instance; // push the view controller onto the stack navigationController.PushViewController(navItem.Controller, true); } else { Console.WriteLine("instance of view controller not created"); } } else { Console.WriteLine("constructor not found"); } } } }