Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone中从camera/UIImagePickerController向iCarousel动态添加图像_Iphone_Ios_Xcode_Icarousel - Fatal编程技术网

如何在iPhone中从camera/UIImagePickerController向iCarousel动态添加图像

如何在iPhone中从camera/UIImagePickerController向iCarousel动态添加图像,iphone,ios,xcode,icarousel,Iphone,Ios,Xcode,Icarousel,我正在使用iCarousel作为shownh。但是我想通过从相机或图像采集器中获取图片来动态添加图像。下面是我的代码 - (void)loadView { [super loadView]; imagesArray = [[NSMutableArray alloc]init] ; // Initialize and configure the carousel carousel = [[iCarousel alloc] initWithFrame:CGRectM

我正在使用iCarousel作为shownh。但是我想通过从相机或图像采集器中获取图片来动态添加图像。下面是我的代码

- (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中。
任何人都可以帮助我。

修改阵列后,您需要在旋转木马上调用重新加载数据。

我在[imagesArray addObject:image]语句之后编写了[carousel reloadData]。它对我很有效。。非常感谢,非常精彩的教程。-(void)按钮已添加:(UIButton*)发送者当我点击封面时,这个方法不是在召唤我。你能告诉我y吗?看看库中包含的“按钮演示”示例,看看你是否能看到你正在做的任何不同的事情。看起来你实际上使用的是一个非常旧的版本,或者你可能遵循了一个过时的教程。从github下载最新版本并检查示例,因为某些方法名称现在已经更改。您不应该用不同的信息不断更新同一个问题。我现在发布的原始答案没有意义,因为我回答了一个不同的问题。堆栈溢出问题旨在为其他寻求答案的开发人员提供参考。请将原始问题放回原处,然后将新问题作为堆栈溢出的单独条目归档。