2

i'm loading bunch of images in coverflow using i carousel but i'm not getting it?..initially i got Signal sigabart issue..after i edited some of the code the view gets displayed...Am i missing something?...

#import "CollectionViewController.h"

@interface CollectionViewController ()
@property (nonatomic, retain) NSMutableArray *items;
@end

@implementation CollectionViewController

@synthesize carousel;
@synthesize items;




- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)dealloc
{

carousel.delegate = nil;
carousel.dataSource = nil;
[items release];

[carousel release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;

}

- (void)viewDidUnload
{
[super viewDidUnload];

self.carousel = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark iCarousel methods

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

 - (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{

return 29;
}


 - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
 {


//create new view if no view is available for recycling
if (view == nil)
{

    view = [NSArray arrayWithObjects:[UIImage imageNamed:@"gal1.jpg"],
            [UIImage imageNamed:@"gal2.jpg"],
            [UIImage imageNamed:@"gal3.jpg"],

            [UIImage imageNamed:@"gal5.jpg"],
            [UIImage imageNamed:@"gal6.jpg"],
            [UIImage imageNamed:@"gal7.jpg"],
            [UIImage imageNamed:@"gal8.jpg"],
            [UIImage imageNamed:@"gal9.jpg"],
            [UIImage imageNamed:@"gal10.jpg"],
            [UIImage imageNamed:@"gal11.jpg"],
            [UIImage imageNamed:@"gal12.jpg"],
            [UIImage imageNamed:@"gal13.jpg"],
            [UIImage imageNamed:@"gal14.jpg"],
            [UIImage imageNamed:@"gal15.jpg"],
            [UIImage imageNamed:@"gal16.jpg"],
            [UIImage imageNamed:@"gal17.jpg"],
            [UIImage imageNamed:@"gal18.jpg"],
            [UIImage imageNamed:@"gal19.jpg"],
            [UIImage imageNamed:@"gal20.jpg"],
            [UIImage imageNamed:@"gal21.jpg"],
            [UIImage imageNamed:@"gal22.jpg"],
            [UIImage imageNamed:@"gal23.jpg"],
            [UIImage imageNamed:@"gal24.jpg"],
            [UIImage imageNamed:@"gal25.jpg"],
            [UIImage imageNamed:@"gal26.jpg"],
            [UIImage imageNamed:@"gal27.jpg"],
            [UIImage imageNamed:@"gal28.jpg"],

}

else {

}

    return view;
 }


 @end

while running on simulator i just get the screen not images?...i got stuck here....

Vishnu
  • 2,243
  • 2
  • 21
  • 44

2 Answers2

1

I have done this already. Here try this:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        //set up carousel data
        wrap = NO;

        self.items = [NSArray arrayWithObjects:[UIImage imageNamed:@"gal1.jpg"],
            [UIImage imageNamed:@"gal2.jpg"],
            [UIImage imageNamed:@"gal3.jpg"],
            [UIImage imageNamed:@"gal5.jpg"],
            [UIImage imageNamed:@"gal6.jpg"],
            [UIImage imageNamed:@"gal7.jpg"],
            [UIImage imageNamed:@"gal8.jpg"],
            [UIImage imageNamed:@"gal9.jpg"],
            [UIImage imageNamed:@"gal10.jpg"],
            [UIImage imageNamed:@"gal11.jpg"],
            [UIImage imageNamed:@"gal12.jpg"],
            [UIImage imageNamed:@"gal13.jpg"],
            [UIImage imageNamed:@"gal14.jpg"],
            [UIImage imageNamed:@"gal15.jpg"],
            [UIImage imageNamed:@"gal16.jpg"],
            [UIImage imageNamed:@"gal17.jpg"],
            [UIImage imageNamed:@"gal18.jpg"],
            [UIImage imageNamed:@"gal19.jpg"],
            [UIImage imageNamed:@"gal20.jpg"],
            [UIImage imageNamed:@"gal21.jpg"],
            [UIImage imageNamed:@"gal22.jpg"],
            [UIImage imageNamed:@"gal23.jpg"],
            [UIImage imageNamed:@"gal24.jpg"],
            [UIImage imageNamed:@"gal25.jpg"],
            [UIImage imageNamed:@"gal26.jpg"],
            [UIImage imageNamed:@"gal27.jpg"],
            [UIImage imageNamed:@"gal28.jpg"],nil];
}
return self;

}

Then in your:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{

    UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[items objectAtIndex:index]]];
    return view;
}

Oh, and another one, kindly edit your numberOfVisibleItemsInCarousel and set it to return 7; so it doesnt waste memory, I think.

Bazinga
  • 2,456
  • 33
  • 76
  • @Dany,you can just disregard or use it, but if you're using it, set its property to BOOL wrap, etc.... if your wrap is NO, it will bump in both sides, but if set to YES, will be like infinite loop. have you tried my answer? – Bazinga Jun 28 '12 at 16:17
  • As Kobe.o4 already said. You should always set your content you want to have displayed either in viewDidLoad or at least in viewDidAppear. It is just like using a UITableView. If this wont work you must have some other errors in your code. – Maverick1st Jun 28 '12 at 16:32
  • I am trying the fetch the songs from device and tried to load the song image on the iCarousel imageview, it is repeatng the objects . How can I correct the same. – Vineesh TP Mar 01 '16 at 17:07
1

iCarousel working code:

Delegate method:

 - (UIView *)carousel:(__unused iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{

   if (view == nil){

    view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 400 , 600)];
    ((UIImageView *)view).image = [UIImage imageNamed:[imageCarosualArray objectAtIndex:index]];
    view.contentMode = UIViewContentModeCenter;
    [view.layer setMasksToBounds:YES];
  }
  return view;
}

Multiple images in Array

CarosualArray =[[NSMutableArray    alloc]initWithObjects:@"test1.png",@"test2.png",@"test3.png",@"test4.png",@"test5.png",@"test6.png",@"test7.png",@"test8.png",@"test9.png", nil];
Shanmugasundharam
  • 2,082
  • 23
  • 32