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

DataForm valuesProvider

7 Answers 75 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 01 Jun 2016, 11:31 PM

I need to get some items from my database in order to display them in a TKDataFormPickerViewEditor. My understanding is that I have to set the valuesProvider property and then if I want to select a specific one I would have to set the valueCandidate property. I can display all of the items correctly but I cannot get it to select a specific one.

 

_dataSource[@"description"].editorClass = [TKDataFormPickerViewEditor class];

_dataSource[@"description"].valuesProvider = @[self.description];

_dataSource[@"description"].valueCandidate = self.description;

 

[self getDescriptions:parameters{

        //this method may be called on a thread other than the main thread and occurs on successfully getting the data back from the database

        NSArray *descriptions = ...;        //gotten from database;
        NSInteger index = [descriptions indexOfObject:self.description];
        _dataSource[@"description"].valuesProvider = descriptions;
        [_dataForm reloadData];    //this reloads the form so that it displays all of the descriptions

        _dataSource[@"description"].valueCandidate = self.description;    //this isn't selecting the one I want
}]; 

7 Answers, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 06 Jun 2016, 11:51 AM
Hi, Ryan,

Thank you for writing.
The correct way to achieve this is to use the selectedIndex property of TKDataFormPickerViewEditor. You should adopt TKDataFormDelegate and implement its dataForm:setupEditor:forProperty:. Consider the code below:
- (void)dataForm:(TKDataForm *)dataForm setupEditor:(TKDataFormEditor *)editor forProperty:(TKEntityProperty *)property {
    if ([editor isKindOfClass:TKDataFormPickerViewEditor.class]) {
        ((TKDataFormPickerViewEditor *)editor).selectedIndex = 2;
        UIPickerView *pickerView = ((UIPickerView *)editor.editor);
        [pickerView selectRow:2 inComponent:0 animated:NO];
    }
}

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
Ryan
Top achievements
Rank 1
answered on 13 Jun 2016, 04:41 PM
This delegate method gets called when the screen first appears. How can I call this after that? Since I am getting data from a database it could take a while to get all of the data that I need. After I get all of my data is when I need to select the correct one.
0
Ryan
Top achievements
Rank 1
answered on 13 Jun 2016, 10:43 PM
Also how would I do this for TKDataFormOptionsEditor? After calling reloadData inside this delegate method it shows all of the correct options but when I set the selectedIndex property of the TKDataFormOptionsEditor, it crashes saying that it is out of bounds.
0
Ryan
Top achievements
Rank 1
answered on 13 Jun 2016, 11:42 PM

For example if I am doing something like this it does not work and crashes on the line where I set the valueCandidate:

 

[[NSOperationQueue new]  addOperationWithBlock:^{

        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            _dataSource[@"desc"].valuesProvider = @[@"test1", @"test2" ];
            _dataSource[@"desc"].valueCandidate = @(1);
        }];

    }];

0
Sophi
Telerik team
answered on 15 Jun 2016, 10:34 AM
Hello Ryan,

In order to preselect value in TKDataFormOptionsEditor you can apply the same login in the setupEditor method.
- (void)dataForm:(TKDataForm *)dataForm setupEditor:(TKDataFormEditor *)editor forProperty:(TKEntityProperty *)property {
    if ([editor isKindOfClass:TKDataFormOptionsEditor.class]) {
        ((TKDataFormOptionsEditor *)editor).selectedIndex = 2;
    }
}
Consider the snippet above.

Regarding the remote data loading, you can't change the initial invocation moment of the delegate methods. However you can call the reloadData method after your data is loaded or perform synchronizing logic in order to display your data properly.

Regards,
Sophi
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
Ryan
Top achievements
Rank 1
answered on 15 Jun 2016, 11:01 PM

When setting the selectedIndex inside the setupeditor method after setting the valuesCandidate property and calling reloadData:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 5 beyond bounds [0 .. 0]'

 

When I examine the options array below it displays more than one option in the debugger:

NSArray *options = ((TKDataFormOptionsEditor*) editor).options;

0
Sophi
Telerik team
answered on 20 Jun 2016, 06:21 AM
Hello Ryan,

When you are using the setupEditor method to preselect an item you don't need to use the valueCandidate property. 
Could you, please, send us a code snippet of your TKDataForm setup or maybe a simple example project where we can actually observe the behavior you are experiencing, this way we will be able to examine your scenario and provide you with solution in short terms. 

Thank you for your understanding.
Looking forward to hearing from you.

Regards,
Sophi
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
Asked by
Ryan
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Ryan
Top achievements
Rank 1
Sophi
Telerik team
Share this question
or