【发布时间】:2014-07-30 08:39:14
【问题描述】:
我正在尝试实现一个从右到左的 iCarousel 对象,两边都有淡入淡出。
所以我将 GtiHub 项目导入到我的应用程序中,将 UIView 分配给 iCarousel...将其链接到我的 MainViewController 上的 IBOutLet 并像 UITableViewController 一样传递 Delegate 和 DataSource。
虽然它不会出现,我不确定是什么导致了这个问题。
我的 iCarousel 数据源是一个 NSMutableArray *items;设计成这样:
for (int i = 0; i < 100; i++)
{
[_items addObject:@(i)];
}
我在 ViewDidLoad 中初始化 iCarousel,如下所示
- (void)viewDidLoad
{
[super viewDidLoad];
//Initialize Carousel
_carousel = [[iCarousel alloc] init];
_carousel.delegate = self;
_carousel.dataSource = self;
//Carousel Testing Data
for (int i = 0; i < 100; i++)
{
[_items addObject:@(i)];
}
//configure carousel
_carousel.type = iCarouselTypeRotary;
}
我的轮播代理方法如下:
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//return the total number of items in the carousel
return [_items count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
((UIImageView *)view).image = [UIImage imageNamed:@"page.png"];
view.contentMode = UIViewContentModeCenter;
label = [[UILabel alloc] initWithFrame:view.bounds];
label.backgroundColor = [UIColor clearColor];
label.font = [label.font fontWithSize:50];
label.tag = 1;
[view addSubview:label];
}
else
{
//get a reference to the label in the recycled view
label = (UILabel *)[view viewWithTag:1];
}
label.text = [_items[index] stringValue];
return view;
}
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
switch (option)
{
case iCarouselOptionFadeMin:
return -0.2;
case iCarouselOptionFadeMax:
return 0.2;
case iCarouselOptionFadeRange:
return 2.0;
default:
return value;
}
}
情节提要中的所有内容似乎都已连接,数据应自行呈现,出了什么问题,我该如何解决这个问题?
【问题讨论】:
-
你能接受让你工作的答案吗?
标签: ios objective-c uiview delegates icarousel