0

我在这里使用 iCarousel 。但是我想通过从相机或图像选择器中拍摄照片来动态添加图像。以下是我的代码,

- (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];


}

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

4

1 回答 1

2

修改数组后需要在轮播上调用reloadData。

于 2012-06-25T11:22:00.053 回答