gpt4 book ai didi

ios - iCarousel 数据源问题

转载 作者:行者123 更新时间:2023-11-29 13:07:29 24 4
gpt4 key购买 nike

我开始使用 iCarousel 但出现了这个错误:

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

我的代码:

#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

最佳答案

我不知道到底是什么问题,但看了其他几篇文章后,我认为这是前 5 个问题,希望对您有所帮助,祝您好运

1.

I've found the most common place this error happens is when you instantiate a view from a xib from within a class that is not the xib's owner.

What I mean by this is you might be calling something similar to this:

[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil]; You're changing the owner, so you have to be sure that the class that self refers to has all the IBOutlet properties needed by "MyView". Usually this is done in Interface Builder, but in this case you're setting your owner programmatically, which means you can't make the connections in IB. When the IBOutlets aren't there, the app tries to make those connections and fails, giving the error you see.

My advice (without knowing any more info than you've given so far) is to check to see if you've made this call without having the proper IBOutlets.

2.

I had connected an UIControl outlet in the interface builder to the IBOutlet in the xib's owner. For some reason, the IBOutlet was deleted from the owner, but the reference to the outlet remained dangling in the xib. This would always give me the error Lesson learnt: When deleting any outlets for vars in the implementation, make sure to unhook the respective connection in the IB

3.

I found the problem, it was because of a button i used in the AboutViewController, i didnt declare the property for that button.

4.

Also when you rename a view, don't forget to delete the reference on File's Owner. It may also raise this error.

5.

Fixed - went to iOS Simulator > Reset Content and Setting

关于ios - iCarousel 数据源问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18253190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com