我有以下的plist,我想在旋转木马上按顺序显示图像。当我调试代码时,我看到索引不是顺序。
我在调试时,首先显示index = 0
,然后下一项是index = 5
(lldb) po [items objectAtIndex:index];
http://charcoaldesign.co.uk/AsyncImageView/Forest/IMG_0351.JPG
(lldb) po [items objectAtIndex:index];
http://charcoaldesign.co.uk/AsyncImageView/Forest/IMG_0358.JPG
以下是实施:
- (void)awakeFromNib
{
//set up data
//your carousel should always be driven by an array of
//data of some kind - don't store data in your item views
//or the recycling mechanism will destroy your data once
//your item views move off-screen
//get image URLs
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Images" ofType:@"plist"];
NSArray *imagePaths = [NSArray arrayWithContentsOfFile:plistPath];
//remote image URLs
NSMutableArray *URLs = [NSMutableArray array];
for (NSString *path in imagePaths)
{
NSURL *URL = [NSURL URLWithString:path];
if (URL)
{
[URLs addObject:URL];
}
else
{
NSLog(@"'%@' is not a valid URL", path);
}
}
self.items = URLs;
}
- (void)dealloc
{
//it's a good idea to set these to nil here to avoid
//sending messages to a deallocated viewcontroller
carousel.delegate = nil;
carousel.dataSource = nil;
}
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
//configure carousel
carousel.type = iCarouselTypeCoverFlow2;
}
- (void)viewDidUnload
{
[super viewDidUnload];
//free up memory by releasing subviews
self.carousel = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//return the total number of items in the carousel
return [items count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if (view == nil)
{
view = [[AsyncImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
view.contentMode = UIViewContentModeScaleAspectFit;
}
//cancel any previously loading images for this view
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:view];
//set image URL. AsyncImageView class will then dynamically load the image
((AsyncImageView *)view).imageURL = [items objectAtIndex:index];
return view;
}
如果有人想测试,这里是github。然后选择并运行动态下载项目