developerWab 2013-02-20 05:58 采纳率: 0%
浏览 3947

iCarousel加载UIView的问题

在应用中用到iCarousel来显示视图列表,但是遇到两个问题:

1.如果设置可见列表的数目为3,索引视图就会显示为3的倍数。

2.如果不设置,那么第一个和最后一个索引视图就会显示。

现在这个重用视图已经把我搞迷糊了。

代码:

-(void)viewWillAppear:(BOOL)animated
{



ViewArray=[[NSMutableArray alloc]init];
for (int i=0; i<26; i++) {
 [ViewArray addObject:views];
    [carousel1 reloadData];

}
NSLog(@"%@",ViewArray);
}


- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//return the total number of items in the carousel
return 26;
}


- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
 UIView *sub=nil;
 if (view==nil) {


view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 900, 387)];

    capitalBG.frame=CGRectMake(28, 29, 221, 329);
    capitalBG.tag=11;
    [view addSubview:capitalBG];

    capitalImage.frame=CGRectMake(28, 29, 221, 329);
           [view addSubview:capitalImage];
    capitalImage.tag=12;
    smallBG.frame=CGRectMake(678, 111, 198, 166);
           [view addSubview:smallBG];
    smallBG.tag=21;
    smallImage.frame=CGRectMake(678, 111, 198, 166);
           [view addSubview:smallImage];
    smallImage.tag=22;

}

else
{

}

capitalBG.frame=CGRectMake(28, 29, 221, 329);
[capitalBG setImage:[UIImage imageNamed:@""]];
[view addSubview:capitalBG];

capitalImage.frame=CGRectMake(28, 29, 221, 329);
[capitalImage setImage:[[[Global ImageCollection]objectForKey:@"CapitalWrite"]objectAtIndex:index]];
[view addSubview:capitalImage];

smallBG.frame=CGRectMake(678, 111, 198, 166);
[smallBG setImage:[UIImage imageNamed:@""]];
[view addSubview:smallBG];

smallImage.frame=CGRectMake(678, 111, 198, 166);
[smallImage setImage:[[[Global ImageCollection]objectForKey:@"SmallWrite"]objectAtIndex:index]];
[view addSubview:smallImage];
 return view;
}


- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
if (option == iCarouselOptionSpacing)
{
    return value * 1.1f;
}

if (option==iCarouselOptionVisibleItems) {
    return 3;
}
return value;
}
  • 写回答

1条回答 默认 最新

  • 梁森森 2018-03-23 10:15
    关注

    参考UITableView的复用

    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备