Как динамически добавлять изображения с камеры /UIImagePickerController в iCarousel в iPhone
Я использую 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 в coverflow. Может ли кто-нибудь, пожалуйста, помогите мне.
1 ответ
Решение
Вам нужно вызвать reloadData на карусели после изменения массива.