【问题标题】:Error When using Multiple Carousel使用多个轮播时出错
【发布时间】:2013-08-29 01:25:59
【问题描述】:

我正在使用多个 iCarousels,并希望从目录中导入图片。我在顶部有 iCarousel 1,在底部有 iCarousel 2。我在用户拍照的 iOS 设备的目录中有大约 6 个文件夹。我想将 iCarousel 1 分配给目录“apple”,将 iCarousel 2 分配给目录“green”。

以下是我到目前为止的代码。但是,当然,由于我正在为 2 个 imageArrays 设置路径,因此会出现“重新定义 ...”的错误。我应该如何使这段代码更简单?

此外,我在imageArray2 = directoryContent; 行还有一个警告说'NSMutableArray *_strong' from 'NSArray *_strong'。我真的想让这一切正常工作。

- (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;
}

【问题讨论】:

    标签: ios objective-c icarousel


    【解决方案1】:

    你声明了一些变量两次。

    你可以这样做:

    -(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;
    }
    

    【讨论】:

    • 谢谢,还有一件事.. 我收到一个错误,说使用未声明的标识符“NSFileManagerdefaultManager”和使用未声明的标识符“documentsDirectory”;你的意思是“NSDocumentDirectory”吗?和错误的接收器类型'NSUInteger'(又名'unsigned int')。你觉得哪里不对?
    • 老兄,你最好阅读 Apple 开发者网站中的 API。我们不能用勺子喂你所有东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 2021-08-31
    • 2022-01-08
    • 2015-05-13
    相关资源
    最近更新 更多