我正在使用多个iCarousels,并希望从目录中导入图片。我在顶部有iCarousel 1,底部有iCarousel 2。我在iOS设备的目录中有大约6个文件夹,用户已经拍摄了照片。我想将iCarousel 1分配到目录“apple”,将iCarousel 2分配到目录“green”。
以下是我的代码,直到现在。但是,当然,由于我正在为2个imageArrays设置路径,因此会出现“重新定义...”的错误。我该如何使这段代码更简单?
此外,我还在'NSMutableArray *_strong' from 'NSArray *_strong'
行警告imageArray2 = directoryContent;
。我真的想让这一切都有效。
- (void)viewDidLoad
{
[super viewDidLoad];
//configure carousel
imageArray1 = (NSMutableArray *)[[NSFileManagerdefaultManager] directoryContentsAtPath: fPath];
NSString *location=@"apple";
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
imageArray1 = directoryContent;
imageArray2 = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *location=@"green";
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
NSArray * directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
imageArray2 = directoryContent;
carousel1.type = iCarouselTypeLinear;
carousel2.type = iCarouselTypeLinear;
}
答案 0 :(得分:0)
你要两次声明一些变量。
你可以这样做:
-(void)viewDidLoad
{
[super viewDidLoad];
//configure carousel
imageArray1 = (NSMutableArray *)[[NSFileManager defaultManager] directoryContentsAtPath: fPath];
NSString *location=@"apple";
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
imageArray1 = [directoryContent mutableCopy];
imageArray2 = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
location=@"green";
fPath = [documentsDirectory stringByAppendingPathComponent:location];
directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
imageArray2 = [directoryContent mutableCopy];
carousel1.type = iCarouselTypeLinear;
carousel2.type = iCarouselTypeLinear;
}