首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iCarousel数据源问题

iCarousel数据源问题
EN

Stack Overflow用户
提问于 2013-08-15 13:02:06
回答 1查看 738关注 0票数 1

我开始使用iCarousel,但得到了以下错误:

代码语言:javascript
复制
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x8372530> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dataSource.'
  1. 我增加了QuartzCore框架
  2. 将iCarousel复制到我的项目中
  3. 从示例中复制XIB

我用了这个例子iCarousel

我的代码:

代码语言:javascript
复制
#import <UIKit/UIKit.h>
#import "iCarousel.h"

@interface UsersViewController : UIViewController <iCarouselDataSource, iCarouselDelegate>

@property (strong, nonatomic) IBOutlet iCarousel *aCarousel;
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (nonatomic) BOOL wrap;

@property (strong, nonatomic) NSMutableArray *animals;
@property (strong, nonatomic) NSMutableArray *descriptions;

- (IBAction)onTapBackButton:(id)sender;

@end




#import "UsersViewController.h"

@interface UsersViewController ()

@end

@implementation UsersViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        _wrap = NO;

        self.animals = [NSMutableArray arrayWithObjects:@"Bear.png",
                        @"Zebra.png",
                        @"Tiger.png",
                        @"Goat.png",
                        @"Birds.png",
                        @"Giraffe.png",
                        @"Chimp.png",
                        nil];

        self.descriptions = [NSMutableArray arrayWithObjects:@"Bears Eat: Honey",
                             @"Zebras Eat: Grass",
                             @"Tigers Eat: Meat",
                             @"Goats Eat: Weeds",
                             @"Birds Eat: Seeds",
                             @"Giraffes Eat: Trees",
                             @"Chimps Eat: Bananas",
                             nil];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.aCarousel.type = iCarouselTypeCoverFlow2;
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Main Actions

- (IBAction)onTapBackButton:(id)sender
{
    [self dissmis];
}


#pragma mark - Main methods

- (void)dissmis
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma - mark iCarousel Delegate

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [self.animals count];
}

- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
    // limit the number of item views loaded concurrently (for performance)
    return 7;
}

- (UIView*)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    // create a numbered view
    view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[self.animals objectAtIndex:index]]];
    return view;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
    return 0;
}

- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
    // usually this should be slightly wider than the item views
    return 240;
}

- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    return self.wrap;
}

- (void)carouselDidScroll:(iCarousel *)carousel
{
    [self.label setText:[NSString stringWithFormat:@"%@", [self.descriptions objectAtIndex:carousel.currentItemIndex]]];
}

@end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-15 13:25:05

我不知道具体的问题是什么,但在看了其他几个帖子后,我认为这是问题的前5位,希望它能帮上忙,祝你好运。

1.

我发现了这个错误最常见的地方是,当您从一个不是xib所有者的类中实例化来自xib的视图时。 我的意思是,你可能会称之为类似的东西: [NSBundle mainBundle loadNibNamed:@"MyView“owner:self options: so ];您正在更改所有者,因此必须确保self引用的类具有"MyView”所需的所有IBOutlet属性。这通常是在Interface中完成的,但在这种情况下,您是以编程方式设置所有者的,这意味着您无法在IB中建立连接。当IBOutlets不在的时候,应用程序试图建立这些连接,但是失败了,给出了你看到的错误。 我的建议(不知道比你目前所提供的信息更多)是检查你是否在没有适当的IBOutlets的情况下打过这个电话。

2.

我已经将接口构建器中的UIControl出口连接到xib所有者的IBOutlet上。由于某种原因,IBOutlet被从所有者中删除,但是对出口的引用仍然在xib中悬空。这将总是给我一个错误的教训:当删除实现中的vars的任何出口时,请确保取消IB中相应的连接。

3.

我发现了这个问题,是因为我在AboutViewController中使用了一个按钮,我没有为那个按钮声明属性。

4.

另外,在重命名视图时,不要忘记删除文件所有者上的引用。它还可能引发此错误。

5.

修正-转到iOS模拟器>重置内容和设置

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18253190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档