Ios 我无法清除的警告

Ios 我无法清除的警告,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我说不兼容的指针类型将NSArray发送到NSString的参数时出错。我也用过仪器,很奇怪,我的应用程序一启动,内存就有90mb左右。我的代码有什么问题 @interface TrashViewController () @end @implementation TrashViewController { NSMutableArray *Trash ; } @synthesize collectionTrash; - (id)initWithNibName:(NSString *

我说不兼容的指针类型将NSArray发送到NSString的参数时出错。我也用过仪器,很奇怪,我的应用程序一启动,内存就有90mb左右。我的代码有什么问题

@interface TrashViewController ()

@end

@implementation TrashViewController {
    NSMutableArray *Trash ;
}
@synthesize collectionTrash;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    filenames = [[NSMutableArray alloc] init];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSArray *locations = [[NSArray alloc]initWithObjects:@"Bottoms", @"Dress", @"Coats", @"Others", @"hats", @"Tops",nil ];
    NSString *fPath = [documentsDirectory stringByAppendingPathComponent:locations];
    NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
    collectionTrash.delegate =self;
    collectionTrash.dataSource=self;
    for(NSString *str in directoryContent)
    {
        NSString *finalFilePath = [fPath stringByAppendingPathComponent:str];
        [filenames addObject:finalFilePath];
    }
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    NSLog(@"j");
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [filenames count];


}



- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"ReuseID";
    TrashCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    UIImageView *imageInCell = (UIImageView*)[cell viewWithTag:1];

    NSString *cacheKey = filenames[indexPath.item];
    imageInCell.image = [self.imageCache objectForKey:cacheKey];

    if (imageInCell.image == nil) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            UIImage *image = [UIImage imageWithContentsOfFile:filenames[indexPath.item]];
            if (image) {
                [self.imageCache setObject:image forKey:cacheKey];
                dispatch_async(dispatch_get_main_queue(), ^{
                    TrashCell *updateCell = (id)[collectionView cellForItemAtIndexPath:indexPath];
                    UIImageView *imageInCell = (UIImageView*)[updateCell viewWithTag:1];
                    imageInCell.image = image;
                });
            }
        });
    }

    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"s:%d", [Trash count]);
    NSString *trashBin = [Trash objectAtIndex:indexPath.row];
    NSLog(@"k%@l",trashBin);
    [filenames removeObjectAtIndex:indexPath.row];
    [Trash removeObjectAtIndex:indexPath.row];

    [self deleteMyFiles:trashBin];
    [collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]];
}
NSString *myFileName;
-(void) deleteMyFiles:(NSString*)filePath {
    NSError *error;

    if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
        [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];

    } else {
        NSLog(@"%@",filePath);
    }
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

    [self.imageCache removeAllObjects];
}

您的问题在viewDidLoad的第5行。-stringByAppendingPathComponent的方法签名为

- (NSString *)stringByAppendingPathComponent:(NSString *)aString
请注意,它需要一个字符串,但您正在传递一个数组

你可能想做的是改变

NSString *fPath = [documentsDirectory stringByAppendingPathComponent:locations];
差不多

NSInteger someIndex = 0; //this will pick the first object in locations, e.g. @"Bottoms".
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:[locations objectAtIndex:someIndex]];
位置是一个字符串数组,因此您需要选择一个,而不是传递整个数组


另外,下次请不要在这里转储代码,而是告诉我们是哪一行导致了错误。如果您能指出导致问题的部分,您更有可能得到快速响应。

您好!感谢您回答我没有得到someIndex,我已将viewdidload中的NSString更改为thing directed,并得到一个未声明标识符someIndex的错误。我也没有得到第一行代码。我应该在下面写什么?@user3001507-第一行只是方法签名,取自文档。不要在代码中实现它。当然,在使用它之前,您需要在某个时刻声明一些索引。它应该是一个介于0和4之间的整数,引用您所在位置的对象-array@user3001507-我添加了一个声明SomeIndexy的示例。您的问题是您未能在问题中包含准确的错误消息,并且您也未能识别错误行。