-1

これが、JSONを使用してUIPickerにデータを入力するシナリオです。

これが私のJSONです

{"id":["232","432"],"contact":["Administrator","Main"]}

データをNSdictionaryに保存し、オブジェクトに変換した後、連絡先を保存するNSarrayを作成しました。

contactNSJSONserializationを使用して、ドロップダウンに値を表示できます。

id選択した連絡先に対応するJSONPOSTリクエストを送信したいと思います。

4

2 に答える 2

2

You're populating your data source incorrectly. You should have a model like this:

contacts : [ { id : "12", name : "Administrator" }, { id : "13", name : "Dude" } ]

After you parse it into the array, in the -pickerView:titleForRow:forComponent: you'll have to pick an NSDictionary value from. Grab the id value from the dictionary fetched from your data source from the -pickerView:didSelectRow:inComponent: method.

edit

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
  NSNumber *idNumber = _contacts[row][@"id"];
  //perform whatever action you need to with selected contact id
}
于 2013-02-19T20:51:47.677 に答える
-1

このようなタグを使用して、IDをUIPickerに設定してみてください。

picker.tag = 232;

于 2013-02-19T20:45:37.457 に答える