【发布时间】:2013-08-30 09:51:25
【问题描述】:
我正在使用 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
【问题讨论】:
-
您看到任何视图/图像吗?您是否检查过调用的方法以及图像数组中是否包含图像?
-
我看不到视图和图像,所以它真的很奇怪。我只能看到背景。我已经放入了 2 个视图并在我的标题中声明了它。是的,数组中应该有图像。我还将更新我的问题,并放置头文件。