我正在使用 iCarousel 来显示我的图像,但奇怪的是我正确地编写了代码并且什么都没有出现。我正在尝试显示目录文件夹中的图像。在目录文件夹中,我有几个文件夹中保存了图像。有什么遗漏吗?我快到了,我做不到。另外,我在 UIView 的最后一个括号中有一个警告,说控件到达非无效函数的末尾。这与这个问题有关吗?我已经退货了,但它不起作用。这是我下面的代码。
-(void)viewDidLoad
{
[super viewDidLoad];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
//configure carousel1
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:@"Tops"];
NSArray *directoryContent = [fileManager directoryContentsAtPath: fPath];
imageArray1 = [directoryContent mutableCopy];
//configure carousel2
fPath = [documentsDirectory stringByAppendingPathComponent:@"Bottoms"];
directoryContent = [fileManager directoryContentsAtPath:fPath];
imageArray2 = [directoryContent mutableCopy];
carousel1.type = iCarouselTypeLinear;
carousel2.type = iCarouselTypeLinear;
}
- (void)viewDidUnload
{
[super viewDidUnload];
//free up memory by releasing subviews
self.carousel1 = nil;
self.carousel2 = nil;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//return the total number of items in the carousel
if (carousel == carousel1)
{
return [imageArray1 count];
}
else
{
return [imageArray2 count];
}
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
UIImage *image;
if (carousel == carousel1)
{
image = [UIImage imageWithContentsOfFile:[imageArray1 objectAtIndex:index]];
((UIImageView *)view).image = image;
}
else
{
image = [UIImage imageWithContentsOfFile:[imageArray2 objectAtIndex:index]];
((UIImageView *)view).image = image;
}
return view;
}}
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display
switch (option)
{
case iCarouselOptionSpacing:
{
if (carousel == carousel2)
{
//add a bit of spacing between the item views
return value * 1.05f;
}
}
default:
{
return value;
}
}
}
随时询问您是否想查看更多代码。
#import <UIKit/UIKit.h>
#import "iCarousel.h"
@interface iCarouselExampleViewController : UIViewController <iCarouselDataSource, iCarouselDelegate>{
NSMutableArray *allImagesArray;
NSMutableArray *imageArray1;
NSMutableArray *imageArray2;
}
@property (nonatomic, retain) IBOutlet iCarousel *carousel1;
@property (nonatomic, retain) IBOutlet iCarousel *carousel2;
@end