Kee*_*ano 4 delegates objective-c uiview ios icarousel
我试图通过两侧淡入淡出实现左侧iCarousel对象的权利.
所以我将GtiHub项目导入我的应用程序,为iCarousel分配了一个UIView ...将它链接到我的MainViewController上的IBOutLet并传递了Delegate以及DataSource,就像UITableViewController一样.
虽然它不会出现,我不确定可能导致这个问题的原因.
我的iCarousel DataSource是一个NSMutableArray*项目; 设计如下:
for (int i = 0; i < 100; i++)
{
[_items addObject:@(i)];
}
Run Code Online (Sandbox Code Playgroud)
我正在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;
}
Run Code Online (Sandbox Code Playgroud)
我的旋转木马代表方法如下:
#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;
}
}
Run Code Online (Sandbox Code Playgroud)
故事板中的所有内容似乎都是连接起来的,数据应该呈现出来,出了什么问题以及如何解决这个问题?
由于在加载视图后设置了DataSource数组(_items):
确保故事板中的轮播视图确实具有控制器的IBOutlet,但不是链接到文件所有者(控制器或视图)的"委托"和"数据源".
设置_carousel.delegate和_carousel.dataSource以"自我"只有经过初始化和更新数据源阵列(在这种情况下_items).
| 归档时间: |
|
| 查看次数: |
954 次 |
| 最近记录: |