如何从camera / UIImagePickerController动态添加图像到iPhone中的iCarousel

时间:2012-06-25 11:03:02

标签: iphone ios xcode icarousel

我正在使用iCarousel,如here所示。但我想通过从相机或图片拾取器拍摄照片来动态添加图像。以下是我的代码,

- (void)loadView {

    [super loadView];
    imagesArray = [[NSMutableArray alloc]init] ;
    // Initialize and configure the carousel
    carousel = [[iCarousel alloc] initWithFrame:CGRectMake(0,50, 100, 100)];
    carousel.autoresizingMask = UIViewAutoresizingFlexibleWidth |   UIViewAutoresizingFlexibleHeight;
    carousel.type = iCarouselTypeCoverFlow;
    carousel.dataSource = self;
    [self.view addSubview:carousel];
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [imagesArray count];

}
- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
    //note: placeholder views are only displayed on some carousels if wrapping is disabled
    return  [imagesArray count];
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
    UIImage *image = [imagesArray objectAtIndex:index];
    UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(0,50,100, 100)] autorelease];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
    [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
    button.tag=index;
    return button;

}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [imagesArray addObject:image];
    NSLog(@"array count is %d",[imagesArray count]);
    [picker dismissModalViewControllerAnimated:YES];


}

即使我能够将图像添加到数组中,只有一个图像出现在coverflow中的imageView中。 任何人都可以帮助我。

1 个答案:

答案 0 :(得分:2)

修改数组后,需要在carousel上调用reloadData。