【发布时间】:2012-11-21 13:27:07
【问题描述】:
https://github.com/nicklockwood/iCarousel/issues/278
我将使用 iCarousel 线性显示图像。 这些图像将被动态获取。 假设有 2 个图像。 但是当我更新 iCarousel 时,背景中也有 2 张图片,如下图。
在调试代码时,我发现viewForItemAtIndex函数在我调用reloadData函数后被调用了2次。
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
所以 iCarousel 中有 4 张图片。
如何防止被调用2次?
请帮我尽快解决这个问题。
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIImageView *puzzlePhoto = nil;
UIImageView *puzzleBG = nil;
UILabel *label = nil;
if (view == nil)
{
view = [[UIImageView alloc] init];
view.frame = CGRectMake(0, 0, 128, 112);
view.backgroundColor = [UIColor clearColor];
view.layer.doubleSided = NO;
puzzlePhoto = [[UIImageView alloc] initWithFrame:CGRectMake(46, 48, 40, 40)];
//! get friend's photo
FForesight *foresightCurrent = (carousel == self.icGameOnwhoAREus) ? [controller.gameManager.m_arrayStartedForesights objectAtIndex:index] : [controller.gameManager.m_arrayEndedForesights objectAtIndex:index];
UIImage *imgPuzzle = [foresightCurrent getPuzzleImage];
if (imgPuzzle)
puzzlePhoto.image = imgPuzzle;
else
puzzlePhoto.image = [UIImage imageNamed:@"puzzle background_small.png"];
puzzleBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 128, 112)];
if (((foresightCurrent.m_intStage & FForesightStage_First) && !foresightCurrent.m_FCreatedByFriend) ||
((foresightCurrent.m_intStage & FForesightStage_Second) && foresightCurrent.m_FCreatedByFriend))
puzzleBG.image = [UIImage imageNamed:@"multi_game_one_item_bg_me.png"];
else
puzzleBG.image = [UIImage imageNamed:@"multi_game_one_item_bg.png"];
//! get friend name
FUser *userFriend = foresightCurrent.m_userFriend;
label = [[UILabel alloc] initWithFrame:CGRectMake(32, 32, 68, 16)];
label.text = userFriend.m_strName;
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont boldSystemFontOfSize:10];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithRed:205.0f/256 green:55.0f/256 blue:2.0f/255 alpha:1];
[view addSubview:puzzlePhoto];
[view addSubview:puzzleBG];
[view addSubview:label];
}
return view;
}
【问题讨论】:
-
我使用了 iCarousel 1.6.3 beta。所以我刚刚升级了 1.7.2(最新版本)。虽然背景图像被删除,但它不能灵活滚动。换句话说,它没有惯性。
-
如果您可以将您放入的代码粘贴到您的 - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 方法中,将会很有帮助。
-
虽然我将您的示例代码(在 iCarousel-master.zip,iCarousel 1.7.2 中)放入我的项目中,但它也不能灵活滚动
标签: iphone objective-c ios tableview icarousel