我从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;
}
)
答案 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;
}