Xamarian iOS Values Provider

11 posts, 1 answers
  1. jon
    jon avatar
    24 posts
    Member since:
    Jun 2009

    Posted 24 Dec 2015 Link to this post

    I'm trying to follow the examples for the iOS Xamarin TKDataForms. How do you get the value providers, say for the EncryptionLevel property in the DataFormGettingStarted example, to push to another view? I'm trying to add this to an app and mine isn't pushing to the new a view like the example is. Is there other code that is required for the push of the new view controller or is it done when I assign the value in the value provider?  
  2. jon
    jon avatar
    24 posts
    Member since:
    Jun 2009

    Posted 28 Dec 2015 Link to this post

    Also, I'm using sliding panel setup for the app; with a left panel menu, a center panel content, and an optional right panel for whatever. The center panel is a UINavigationController with the desired ViewController. Could this be what's throwing off the value provider? If so, how do I make it recognize the center panel navigation controller and push a new list view of the value provider? 
  3. DevCraft banner
  4. Answer
    Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 28 Dec 2015 Link to this post

    Hello, Jon,

    Thank you for contacting us.

    To show the values for the property in a separate view the view controller that holds the data form should inherit from TKDataFormViewController and you should use a UINavigationController as a container controller. Then you should set editorClass of the TKEntityProperty to be TKDataFormOptionsEditor. Please consider the code snippet below:
    public class DataFormGettingStarted : TKDataFormViewController
    {
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            // ...
            this.dataSource["EncryptionLevel"].ValuesProvider = NSArray.FromStrings(new string[] { "FIPS Compliant", "High", "Client Compatible", "Low" });
            this.dataSource["EncryptionLevel"].EditorClass = new Class(typeof(TKDataFormOptionsEditor));
            // ...
        }
    }

    I hope this helps. If you need further assistance do not hesitate to contact us.

    Regards,
    Adrian
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. jon
    jon avatar
    24 posts
    Member since:
    Jun 2009

    Posted 30 Dec 2015 in reply to Adrian Link to this post

    Attached is a sample of the issue I'm having
  6. jon
    jon avatar
    24 posts
    Member since:
    Jun 2009

    Posted 30 Dec 2015 Link to this post

    Still not working. I have a model field:

    [Export("TimeZone")]
    public byte TimeZone { get; set; }

     And my View Controller:

    namespace Test
    {
        public partial class ViewController : TKDataFormViewController
        {
            TKDataForm dataForm;
            TKDataFormEntityDataSourceHelper dataSource;
            DataFormDelegate dataFormDelegate;
            m_Account mobileAccount;
            UIButton btnSaveAccount;

            public ViewController ()
            {
                Title = "Example";
                mobileAccount = new m_Account ();
            }

            public override void ViewDidLoad ()
            {
                base.ViewDidLoad ();
                View.BackgroundColor = UIColor.White;

                //Account table
                this.dataSource = new TKDataFormEntityDataSourceHelper (this.mobileAccount);
                this.dataFormDelegate = new DataFormDelegate ();

                this.dataForm = new TKDataForm ();
                this.dataForm.Frame = new CGRect (0, this.NavigationController.NavigationBar.Bounds.Height, View.Bounds.Width, View.Bounds.Height - 66);
                this.dataForm.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                this.dataForm.BackgroundColor = UIColor.White;

                this.dataSource ["TimeZone"].DisplayName = "Time Zone";

                //Timezone is a byte coming from the api
                this.dataSource ["TimeZone"].ValuesProvider = NSArray.FromStrings (new string[] {"Central","Mountain","Pacific","Eastern"});
                this.dataSource["TimeZone"].EditorClass = new ObjCRuntime.Class(typeof(TKDataFormOptionsEditor));

                this.dataSource.AddGroup (" ", new string[] {
                    "TimeZone"
                });

                this.dataForm.Delegate = this.dataFormDelegate;
                this.dataForm.WeakDataSource = this.dataSource.NativeObject;
                this.dataForm.CommitMode = TKDataFormCommitMode.Immediate;


                btnSaveAccount = new UIButton (new CGRect (0, this.dataForm.Frame.Size.Height, this.View.Bounds.Width, 66));
                btnSaveAccount.SetTitle ("Save My Account", UIControlState.Normal);
                btnSaveAccount.BackgroundColor = UIColor.Green;
                btnSaveAccount.SetTitleColor (UIColor.White, UIControlState.Normal);
                btnSaveAccount.AddTarget (this, new ObjCRuntime.Selector ("saveMyAccount"), UIControlEvent.TouchUpInside);

                View.AddSubview (this.dataForm);
                View.AddSubview (btnSaveAccount);
            } 

            [Export ("saveMyAccount")]
            void saveMyAccount()
            {
            }
        }

        class DataFormDelegate : TKDataFormDelegate
        {
            public override void UpdateEditor (TKDataForm dataForm, TKDataFormEditor editor, TKEntityProperty property)
            {
                if (property.Name == "TimeZone") {
                    editor.TextLabel.TextColor = UIColor.Black;
                    editor.BackgroundColor = UIColor.Clear;
                    ((TKDataFormOptionsEditor)editor).SelectedOptionLabel.TextColor = UIColor.Black;
                    ((TKDataFormOptionsEditor)editor).SelectedOptionLabel.TextAlignment = UITextAlignment.Left;
                }
            }
        }
    }

     

  7. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 04 Jan Link to this post

    Hi, Jon,

    Can you confirm that your TKDataFormViewController subclass is inside UINavigationController?

    Regards,
    Adrian
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. jon
    jon avatar
    24 posts
    Member since:
    Jun 2009

    Posted 04 Jan in reply to Adrian Link to this post

    Yes I can, here is my app delegate file. I'm using a sliding panel component with a left, middle, and optional right view. The content is being loaded into the center panel for the data form.

    public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
            {
                JASidePanelController viewController = new JASidePanelController();
                viewController.ShouldDelegateAutorotateToVisiblePanel = false;
                viewController.CenterPanel = new UINavigationController (new ViewController ());
                viewController.LeftPanel = new UINavigationController (new MenuViewController ());

                this.Window = new UIWindow (UIScreen.MainScreen.Bounds);
                this.Window.RootViewController = viewController;
                this.Window.MakeKeyAndVisible ();

                return true;
            }

  9. jon
    jon avatar
    24 posts
    Member since:
    Jun 2009

    Posted 04 Jan in reply to Adrian Link to this post

    What's even weirder is if I use the EncryptionLevel example from above, it works. The only difference is my model is a byte instead of an int but if I change my model property to an int, it still doesn't work for my example with time zones.
  10. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 05 Jan Link to this post

    Hi, Jon, 

    I am not able to reproduce this issue. Could you please send me a sample project that can be compiled and the issue occurs so I could investigate it further and provide you with a solution?

    I am looking forward to your reply.

    Regards,
    Adrian
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  11. jon
    jon avatar
    24 posts
    Member since:
    Jun 2009

    Posted 08 Jan in reply to Adrian Link to this post

    I found the issue. I was instantiating a new data form instead of using the virtual class. Thanks
  12. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 11 Jan Link to this post

    Hi, Jon,

    Thank you for the feedback. I am glad that the issue is solved.
    If you have further questions, do not hesitate to contact us.

    Regards,
    Adrian
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner