Muthu Raj Muthu Raj - 1 year ago 121
Objective-C Question

Data is not loading in UIpickerview

I am trying to load the data from web service into UI picker view. It shows up as blank. Below is my code.

NSMutableArray * flooring;
NSDictionary *dictionary;
NSString *floorname;
NSString *floorid;

- (void)viewDidLoad {
floorname = @"Name";
floorid = @"IntFloorId";
NSString *strURL=[NSString stringWithFormat:@""];
NSData *jsonSource = [NSData dataWithContentsOfURL:
[NSURL URLWithString:strURL]];
id jsonObjects = [NSJSONSerialization JSONObjectWithData:
jsonSource options:NSJSONReadingMutableContainers error:nil];
for (NSDictionary *dataDict in jsonObjects) {
NSString *Name = [dataDict objectForKey:@"Name"];
NSString *floorid1 = [dataDict objectForKey:@"IntFloorId"];
dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
Name,floorname,floorid1,floorid, nil];
[flooring addObject:dictionary];

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

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
return flooring.count;
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
NSDictionary *tmpDict = [flooring objectAtIndex:row];
NSString * f = [tmpDict objectForKey:@"Name"];return f;

Any help will be appreciated.

Answer Source

flooring is never initialized so it appears empty.


flooring = [NSMutableArray array];

in your viewDidLoad method.

Also learn to use your debugger. You would have found this long ago if you debugged your code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download