This is a migrated thread and some comments may be shown as answers.

TKDataForm TableViewCell

7 Answers 84 Views
DataForm - Xamarin.iOS
This is a migrated thread and some comments may be shown as answers.
jon
Top achievements
Rank 1
jon asked on 28 Jan 2016, 04:58 PM
Is it possible to have a group that shows normal UITableView cells in a data form?

7 Answers, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 01 Feb 2016, 09:39 AM
Hi, Jon,

Thank you for contacting us.

Internally TKDataForm does not use UITableView and it does not display UITableView cells. It uses UIScrollView in which the form layouts its editors. If you need to display custom editors, this is possible by subclassing TKDataFormEditor and override its methods. This way you can layout the editor to suit your needs. Consider the code snippet below:
public class CustomEditor : TKDataFormEditor
{
    // implement custom editor;
}

Then you can use you custom editor by setting the EditorClass property of TKEntityProperty:
this.dataSource["MyProperty"].EditorClass = new ObjCRuntime.Class(typeof(CustomEditor));

I hope this helps. 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
0
jon
Top achievements
Rank 1
answered on 08 Feb 2016, 03:25 AM
So I could replace the whole cell with just a custom editor view? What I'm trying to do is display a parent object but have a group in the data form that will show the title for the child object (for example: parent object is automobiles and the children are cars, SUV, etc...). How would I loop through each of those objects and display a custom editor view?
0
Adrian
Telerik team
answered on 10 Feb 2016, 03:20 PM
Hello, Jon,

I am not sure that I understand the scenario you are after, however you can provide a custom editor for a property by using the form's data source. You should set the EditorClass property of the TKEntityProperty that you are going to edit in the data form. Consider the code below:
this.dataSource["Email"].EditorClass = new Class (typeof(MyCustomEditor));

This way the form will instantiate you custom editor to edit the corresponding property.
I hope this helps.

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
0
jon
Top achievements
Rank 1
answered on 10 Feb 2016, 07:20 PM

I have a parent object that has lists inside of it of entities associated with it. The scenario I'm asking about is, is it possible to create a custom editor for each one of the child associated lists in the parent with something just like a label that would display the each child entity's name and maybe another property? 

0
Adrian
Telerik team
answered on 15 Feb 2016, 04:45 PM
Hi, Jon,

A code snippet describing the structure of the object that you want to edit in the data form would be helpful since I am still not sure if I understand the case correctly. Currently TKDataForm does not support editing of complex objects that are properties of your business object. This is logged in our feedback portal and will be implemented in one of our future releases.
However if you need to create an editor that displays a selectable list of items for a category in a UITableView you should use TKDataFormOptionsEditor. Consider the code snippet below:
this.dataSource ["Automobiles"].ValuesProvider = NSArray.FromStrings (new string[] { "Sedan", "Coupe", "Convertible", "Touring" });
this.dataSource["Automobiles"].EditorClass = new ObjCRuntime.Class(typeof(TKDataFormOptionsEditor));

I hope this is helpful.

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
0
jon
Top achievements
Rank 1
answered on 15 Feb 2016, 11:52 PM
Attached is an example of the format I am trying to create. There is a parent class that has associated children objects of Assignments and To-Dos with cells that show the child name and date. Is something like this possible in the data form using a custom editor?
0
Adrian
Telerik team
answered on 18 Feb 2016, 04:27 PM
Hi, Jon,

Such scenario can be achieved with custom table view editor for TKDataForm. You should use your collection as a data source for the table view. The code snippet below demonstrates how such editor could be implemented:
public class TableViewEditor : TKDataFormEditor
    {
        UITableView tableView;
        NSArray options;
        TableViewDataSource tableViewDataSource;
 
        public TableViewEditor() : base () {
            tableView = new UITableView ();
            tableViewDataSource = new TableViewDataSource (this.options);
            tableView.WeakDataSource = tableViewDataSource;
            this.AddSubview (tableView);
            this.GridLayout.AddArrangedView (this.tableView);
            TKGridLayoutCellDefinition btnDef = this.GridLayout.DefinitionForView (this.tableView);
            btnDef.Row = new NSNumber (0);
            btnDef.Column = new NSNumber (3);
        }
 
        public override TKEntityProperty Property {
            get {
                return base.Property;
            }
            set {
                base.Property = value;
                options = value.ValuesProvider;
                tableViewDataSource.options = this.options;
            }
        }
 
        public override UIView Editor {
            get {
                return this.tableView;
            }
        }
    }
 
    class TableViewDelegate : UITableViewDelegate {
    }
 
    class TableViewDataSource : UITableViewDataSource {
        public NSArray options;
        public TableViewDataSource (NSArray options) : base () {
            this.options = options;
        }
 
        public override nint NumberOfSections (UITableView tableView)
        {
            return 1;
        }
 
        public override nint RowsInSection (UITableView tableView, nint section)
        {
            return (nint)options.Count;
        }
 
        public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell ("cell");
            if (cell == null) {
                cell = new UITableViewCell ();
            }
 
            cell.TextLabel.Text = options.GetItem<NSString> ((nuint)indexPath.Row);
            return cell;
        }
    }

To use the editor and provide its data you should use the appropriate entity property:
this.dataSource["InfoProtocol"].ValuesProvider = NSArray.FromStrings(new string[] { "L2TP", "PPTP", "IPSec" });
this.dataSource["InfoProtocol"].EditorClass = new Class(typeof(TableViewEditor));

For the sake of simplicity in the example above I have been using an array of strings. In your case the ValuesProvider should be the collection of Assignments/ToDos that you need to display in the table view and you should modify the table view cell according to the data that you need to show from the Assignement/ToDo object.

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
Tags
DataForm - Xamarin.iOS
Asked by
jon
Top achievements
Rank 1
Answers by
Adrian
Telerik team
jon
Top achievements
Rank 1
Share this question
or