如何从数据库中获取数据并显示uipickerview

时间:2015-09-01 11:38:50

标签: ios objective-c sqlite uipickerview

我从sqlite3获取数据,现在我需要在UIPicker视图中显示这些值,任何人都可以帮助我,

我从数据库获得了响应,如

stateName: (
        {
        "state_name" = Alabama;
    },
        {
        "state_name" = Arizona;
    },
        {
        "state_name" = Arkansas;
    },
        {
        "state_name" = California;
    },
        {
        "state_name" = Colorado;
    },
        {
        "state_name" = Connecticut;
    },
        {
        "state_name" = Delaware;
    },
        {
        "state_name" = "District of Columbia";
    },
        {
        "state_name" = Florida;
    },
        {
        "state_name" = Georgia;
    },
        {
        "state_name" = Idaho;
    },
        {
        "state_name" = Illinois;
    },
        {
        "state_name" = Indiana;
    },
        {
        "state_name" = Iowa;
    },
        {
        "state_name" = Kansas;
    },
        {
        "state_name" = Kentucky;
    },
        {
        "state_name" = Louisiana;
    },
        {
        "state_name" = Maine;
    },
        {
        "state_name" = Maryland;
    },
        {
        "state_name" = Massachusetts;
    },
        {
        "state_name" = Michigan;
    },
        {
        "state_name" = Minnesota;
    },
        {
        "state_name" = Mississippi;
    },
        {
        "state_name" = Missouri;
    },
        {
        "state_name" = Montana;
    },
        {
        "state_name" = Nebraska;
    },
        {
        "state_name" = Nevada;
    },
        {
        "state_name" = "New Hampshire";
    },
        {
        "state_name" = "New Jersey";
    },
        {
        "state_name" = "New Mexico";
    },
        {
        "state_name" = "New York";
    },
        {
        "state_name" = "North Carolina";
    },
        {
        "state_name" = "North Dakota";
    },
        {
        "state_name" = Ohio;
    },
        {
        "state_name" = Oklahoma;
    },
        {
        "state_name" = Oregon;
    },
        {
        "state_name" = Pennsylvania;
    },
        {
        "state_name" = "Rhode Island";
    },
        {
        "state_name" = "South Carolina";
    },
        {
        "state_name" = "South Dakota";
    },
        {
        "state_name" = Tennessee;
    },
        {
        "state_name" = Texas;
    },
        {
        "state_name" = Utah;
    },
        {
        "state_name" = Vermont;
    },
        {
        "state_name" = Virginia;
    },
        {
        "state_name" = Washington;
    },
        {
        "state_name" = "West Virginia";
    },
        {
        "state_name" = Wisconsin;
    },
        {
        "state_name" = Wyoming;
    }
)

1 个答案:

答案 0 :(得分:0)

UIPickerView有委托方法。 #pragma mark - PickerView代理

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

//=====================================================================================
//Customize Number of rows in Component
//=====================================================================================
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {

    if([genreList count] != 0)
    {
        return [genreList count];
    }
    else
    {
        return 0;
    }
}


//=====================================================================================
//Set title For Row
//=====================================================================================
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row1 forComponent:(NSInteger)component {

    if([genreList count] != 0)
    {
        return [genreList objectAtIndex:row1];
    }
    else
    {
        return nil;
    }


    //return 4;

}