示例#1
0
 //
 public static void ReloadCellModel(this UITableView table, CellModel cellModel)
 {
     var path = cellModel.Path();
       if ( path != null )
       {
     table.ReloadRows(new [] { path }, UITableViewRowAnimation.Automatic);
       }
 }
示例#2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

              View.BackgroundColor = UIColor.Green;

              Title = "YxTableTest";

              _view = new UITableView(new CGRect(), UITableViewStyle.Grouped);
              View.Add(_view);

              //_view.SeparatorInset = UIEdgeInsets.Zero;
              //_view.LayoutMargins = UIEdgeInsets.Zero;
              //_view.SeparatorStyle = UITableViewCellSeparatorStyle.None;

              _view.FitToParent();

              var source = new TableSource();

              Section section;

              // -----------------------

              section = new Section();
              section.Header = "Default cell";
              section.Footer = "---";

              var defaultCellFactory = new DefaultCellFactory();

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              defaultCellFactory,
              new ItemWithTitle { Title = "foo" }
            ));

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              defaultCellFactory,
              new ItemWithTitle { Title = "bar" }
            ));

              source.Sections.Add(section);

              // -----------------------

              section = new Section();
              section.Header = "Subtitle";

              section.Cells.Add(
            new CellModel<ItemWithTitleAndSubtitle>(
              Singleton<SubtitleCellFactory>._,
              new ItemWithTitleAndSubtitle { Title = "abc", SubTitle = "123" }
            ));

              source.Sections.Add(section);

              // -----------------------

              section = new Section();
              section.Header = "Switch cell";

              var changingModel = new ItemWithTitle { Title = "This will change when switch is toggled" };
              var changingCell = new CellModel<ItemWithTitle>(defaultCellFactory, changingModel);
              section.Cells.Add( changingCell );

              var switchCellFactory1 = new SwitchCellFactory { InitialState = true };
              var switchCellFactory2 = new SwitchCellFactory {
            InitialState = false,
            CellSelected = (cell) => MsgBox.Show(cell.Model.Title, "Cell selected", new [] {"OK"}),
            Toggled = (cell) => {
              changingCell.Model.Title = "You changed me!";
              _view.ReloadCellModel(changingCell);
            }
              };

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              switchCellFactory1,
              new ItemWithTitle { Title = "foo" }
            ));

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              switchCellFactory2,
              new ItemWithTitle { Title = "Toggling this will change above text. Hopafully." }
            ));

              source.Sections.Add(section);

              // -----------------------

              section = new Section();
              section.Header = "Custom 1";

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              Singleton<CustomCellFactory1>._,
              new ItemWithTitle { Title = "abc" }
            ));

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              Singleton<CustomCellFactory1>._,
              new ItemWithTitle { Title = "def" }
            ));

              source.Sections.Add(section);

              // -----------------------

              section = new Section();
              section.Header = "Custom 2";
              //section2.Footer = "Footer 2";

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              Singleton<CustomCellFactory2>._,
              new ItemWithTitle { Title = "abc" }
            ));

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              Singleton<CustomCellFactory2>._,
              new ItemWithTitle { Title = "def" }
            ));

              source.Sections.Add(section);

              // -----------------------

              _view.Source = source;
        }