我正在iCarousel
用作老虎机,对于那些不知道iCarousel
它是UIScrollview
with(分页,滚动视图)的人。所以在我的应用程序中,我滚动它,然后当它停止时它会显示图像(结果)3秒,然后弹出一个按钮,如果你按下按钮,它将删除视图(图像结果)然后再次旋转。
这是我删除轮播视图的方法:
NSInteger CurrentImage = carousel.currentItemIndex;
[carousel removeItemAtIndex:CurrentImage animated:YES];
[images removeObjectAtIndex:CurrentImage];
但是当carousel.numberOfItems
剩下 1 个项目时,它不会滚动,而是卡在那里。
所以我做了一种方法让它滚动,即使它只剩下 1 个项目(索引)。
我用最后一个索引插入了它,所以我尝试了这个:
[self.carousel insertItemAtIndex:0 animated:NO];
(但不起作用)
然后我尝试了另一个:
int lastObject = [images objectAtIndex: ([images count]-1)]
[self.carousel insertItemAtIndex:lastObject animated:NO];
(仍然不起作用)
还有这个:
int count = [images count];
[images objectAtIndex:count - 1];
(仍然没有运气)
我做错了吗?或者还有什么其他方法?或者我可以复制最后一个视图吗?谢谢您的帮助。
编辑: 方法
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
if ([images count] == 1 || [self.carousel numberOfItems] == 1)
return 2;
return [images count];
}
- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
//limit the number of items views loaded concurrently (for performance reasons)
return 7;
}
- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
if (index >= [images count] || index >= [carousel numberOfItems]) {
index = 0;
}
NSDictionary *obj = [images objectAtIndex:index];
view = [[UIImageView alloc] initWithImage:[obj objectForKey:@"image"]];
view.tag = index;
return view;
}
- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
//note: placeholder views are only displayed on some carousels if wrapping is disabled
return 0;
}
- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
//usually this should be slightly wider than the item views
return 400;
}
- (BOOL)carousel:(iCarousel *)carousel shouldSelectItemAtIndex:(NSInteger)index{
return 5;
}
- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
//wrap all carousels
return wrap;
}
删除方法:
-(void) deleteItem{
//Removes the object chosen
if (carousel.numberOfItems >= 1)
{
NSInteger index = carousel.currentItemIndex;
[carousel removeItemAtIndex:index animated:YES];
//[images removeObjectAtIndex:index];
//[images replaceObjectAtIndex:index withObject:[NSNull null]];
}
}