1
votes

I am using icarousel to show coverflow in my project.. i am using uiview as an carousel item which contains labels and image view. The data for the carousel is coming from call to web service and i bind that data to the labels and image view of uiview which i used as an carousel item. Now issue is that as data from web service is large so it takes much time to load the data and bind it to icarousel, it almost freezes my app.. Now what i want is something like asynchronous downloading data and binding it to the icarousel so that it gets displayed immediately and user would not have to wait until all the data from the server is being downloaded..

Any help would be appreciated.. thanks

1

1 Answers

0
votes

I would suggest using something like AFNetworking to perform the retrieval of the data async. Once you get the response back, iterate over all the data objects you got back and call [carousel insertItemAtIndex:index animated:YES]; like this:

@interface ViewController ()

@property (nonatomic, retain) NSMutableArray *items;

@end

// This is a sample function, actual implementation will look different for you
- (void)callBackFromAsyncWebService:(NSArray*)data 
{
    for (id dataObj in data) {
        [self insertItem:dataObj];
    }
}

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [items count];
}

- (IBAction)insertItem:(id)item
{
    NSInteger index = MAX(0, carousel.currentItemIndex);
    [items insertObject:item atIndex:index];
    [carousel insertItemAtIndex:index animated:YES];
}