ConnectionDidFinishLoading之后的iOS Execute方法

时间:2015-05-25 18:03:34

标签: ios nsurlconnection uipickerview

我目前遇到的问题是,在我的Array在ConnectionDidFinishLaunching中填充之前,我的UIPickerView numberOfComponents被调用了。这导致0行。

视图顶部的2个属性:

@property NSArray *JSONArray;
@property (strong,nonatomic) NSMutableData *data; //De Data
@property (weak, nonatomic) IBOutlet UIPickerView *expositionPicker; //picker

viewDidLoad中:

NSURL *url = [NSURL URLWithString:@"http://dtprojecten.ehb.be/~IPBOZAR3C/API/GetAllExpositions.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

FinishLaunchOptions(也正确实现了某些方法,如didReceive数据)

-(void)connectionDidFinishLoading:(NSURLConnection*)connection{
NSLog(@"DidFinishLoading");
NSLog(@"Succeeded! Received %lu bytes of data",(unsigned long)[self.data length]);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

self.JSONArray = [NSJSONSerialization JSONObjectWithData:_data options:0 error:nil];
NSLog(@"JSON: %@", self.JSONArray);

NSLog(@"JSONARRAY: %lu",(unsigned long)self.JSONArray.count); //CHECK
NSLog(@"objectAtIndex 0 = %@", [[self.JSONArray objectAtIndex:0] objectForKey:@"name"]); //CORRECT
NSLog(@"objectAtIndex 1 = %@", [[self.JSONArray objectAtIndex:1] objectForKey:@"name"]); //CORRECT

//[self.expositionPicker reloadInputViews];

[self.expositionPicker reloadAllComponents]; //NOT WORKING ?}


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


- (long)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (self.JSONArray != NULL)
{
    NSLog(@"Aantal rijen moeten voorzien worden:%lu", [self.JSONArray count]); //WRONG

    return [self.JSONArray count];
} else {
    NSLog(@"Deze array is leeg!");
    return 0;
} }

- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [[self.JSONArray objectAtIndex:row] objectForKey:@"name"]; }

任何人都可以帮我解决这个问题吗?

谢谢!

0 个答案:

没有答案