i have to fill 2 NSDictionary and an Array (which will bind to one Pickerview one at a time) on View load with the values returning from the server...
I tried Replacing [request startSynchronous] with
[request startAsynchronous] but it gives problem it fill only the
array( arryColor) as the -(void)viewDidLoad executes completely first before the
- (void)requestFinished
ASIHTTPRequest *)request
and makes the searchValue=Color
Pickerview functions
#pragma mark TextField view
I tried Replacing [request startSynchronous] with
[request startAsynchronous] but it gives problem it fill only the
array( arryColor) as the -(void)viewDidLoad executes completely first before the
- (void)requestFinished
and makes the searchValue=Color
Code:
int flgTextField;
static NSString *searchValue;
- (void)viewDidLoad {
[super viewDidLoad];
flgTextField =1;
dictPrice = [[NSMutableDictionary alloc] init];
dictCategory = [[NSMutableDictionary alloc] init];
arryColor = [[NSMutableArray alloc] init];
searchValue=@"Category";
[self fillPickerView:searchValue];
searchValue=@"Price";
[self fillPickerView:searchValue];
searchValue=@"Color";
[self fillPickerView:searchValue];
[pickerview reloadAllComponents];
}
Code:
-(void)fillPickerView:(NSString *)value{
NSString *trackurl= [[NSString alloc] initWithFormat:@"http://abc.com/combolist=%@",value];
NSURL *url = [NSURL URLWithString:trackurl];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[trackurl release];
[request setDelegate:self];
[request [COLOR="Red"]startSynchronous[/COLOR]];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
NSArray *arry;
if (searchValue==@"Category") {
arry= [responseString componentsSeparatedByString:@","];
for (int i=0; i<[arry count]; i++) {
NSArray *arryValue = [[arry objectAtIndex:i] componentsSeparatedByString:@"~"];
[dictCategory setObject:[arryValue objectAtIndex:1] forKey:[arryValue objectAtIndex:0]];
}
}
else if (searchValue==@"Price") {
arry= [responseString componentsSeparatedByString:@","];
for (int i=[arry count]-1; i>=0; i--) {
NSArray *arryValue = [[arry objectAtIndex:i] componentsSeparatedByString:@"~"];
[dictPrice setObject:[arryValue objectAtIndex:1] forKey:[arryValue objectAtIndex:0]];
}
}
else if (searchValue==@"Color") {
arry = [responseString componentsSeparatedByString:@"~"];
[arryColor setArray:arry];
}
}
Pickerview functions
Code:
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
switch (flgTextField) {
case 1:
return [dictPrice count];
case 2:
return [dictCategory count];
case 3:
return [arryColor count];
case 4:
return [arrySort count];
default:
return 0;
}
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
switch (flgTextField) {
case 1:
return [dictPrice objectForKey:[[dictPrice allKeys] objectAtIndex:row]];
break;
case 2:
return [dictCategory objectForKey:[[dictCategory allKeys] objectAtIndex:row]];
break;
case 3:
return [arryColor objectAtIndex:row];
break;
case 4:
return [arrySort objectAtIndex:row];
break;
default:
return [NSString stringWithString:@"Not Specified"];
break;
}
}
#pragma mark TextField view
Code:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Make a new view, or do what you want here
flgTextField = textField.tag;
[pickerview reloadAllComponents];
return NO;
}