I have a silly doubt, but I need to understand it properly. I have referred few posts on this but they are still confusing to me.
I have an array which consists of set of urls which i got from parsing a xml and I store the array like this:
Parser.m
else if([elementName isEqualToString:@"image"]){
self.img.imageUrl = self.currentElement;
[[self URL_array]addObject:img.imageUrl];
}
and if I log the contents it gives the contents as follows:
the URL ARRAY IS --------------------->>>>(
"http://www.bedfordevents.co.uk/images/stories/template/GallerySlideshow/b10.jpg\n",
"http://www.bedfordevents.co.uk/images/stories/template/GallerySlideshow/b11.jpg\n",
"http://www.bedfordevents.co.uk/images/stories/template/GallerySlideshow/b12.jpg\n",
"http://www.bedfordevents.co.uk/images/stories/template/GallerySlideshow/b13.jpg\n",
I need to pass this array to another class/View controller,for which I’ve been doing like this in Parser.m file
ViewController *control = [[ViewController alloc]init];
control.image_array = URL_array;
View controller has an array image_array
and I call the array in ViewController.m like this
NSLog(@"array is----->>%@ ",self.image_array);
But the image_array returns null;
I believe I’m doing it wrong somewhere, Can anyone point out my mistake and help me out?
Thank you.
EDIT
code updated.
now I have a method in ViewController as said
-(void)updateImageArray:(NSMutableArray *)imageArray{
self.image_array = [NSMutableArray arrayWithArray:imageArray];
NSLog(@"array is in here-------->>>>%@",self.image_array);
}
and called
[control updateImageArray:URL_array];
in my Parser.m and the array is displayed in log in ViewController.m and its working
Thank you
From what you wrote in comments, it seems that the
viewDidLoadis called BEFORE you set image_array.You could add the method
[control updateImageArray:URL_array]and then inside this method setself.image_array = [NSArray arrayWithArray:URL_array];and refresh UI as desired