【问题标题】:icarousel is not showing up for ios7icarousel 没有出现在 ios7 上
【发布时间】:2014-04-07 07:04:53
【问题描述】:

我想在我的项目中使用 icarousel。我已经从 github 下载了 icarousel。当我添加 icarousel 时,它没有出现。可能是什么原因?

这是我的代码:

PhotoPreview.h

#import <UIKit/UIKit.h>
#import "iCarousel.h"

@interface PhotoPreview : UIViewController <iCarouselDataSource,iCarouselDelegate>

@property (weak, nonatomic) iCarousel *carousel;

@end

PhotoPreview.m

#import "PhotoPreview.h"

@interface PhotoPreview (){
    NSMutableArray *items;
}

@end

@implementation PhotoPreview

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _carousel.type = iCarouselTypeCoverFlow2;
    [self.view addSubview:_carousel];
}

-(void)viewWillAppear:(BOOL)animated{
    items = [[NSMutableArray alloc] init];
    for (int i = 0; i < 100; i++)
    {
        [items addObject:@(i)];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    NSLog(@"%d",items.count);
    return 5;
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    UILabel *label = nil;
    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.textAlignment = NSTextAlignmentCenter;
        label.font = [label.font fontWithSize:50];
        label.tag = 1;
        [view addSubview:label];
    }
    else
    {
        label = (UILabel *)[view viewWithTag:1];
    }
    label.text = @"AAA";
    return view;
}

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

@end

【问题讨论】:

    标签: ios uiviewcontroller uiimageview icarousel


    【解决方案1】:

    几天前我探索了它,我记得这部分是一个连接到一个视图的 IBOutlet,该视图的类从 Interface builder 设置为 iCarousel

    @property (weak, nonatomic) IBOutlet iCarousel *carousel;
    

    此外,IB 也联系了代表。

    编辑:

    看你的代码viewDidLoad:

    你还没有初始化_carousel对象,它应该通过IB添加。看看我附上的图片。

    图片1:

    图片2:

    图像3:

    另外,请查看随库提供的示例。

    希望对你有帮助!

    【讨论】:

    • 一开始我照你说的做了。但我无法在 IB 中获取此对象。
    • 获取一个 UIView 并将其设置为 iCarousel。
    • 没有帮助。我无法从 IB 设置委托和数据源。
    猜你喜欢
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    • 2016-12-14
    相关资源
    最近更新 更多