名为'count'的多个方法发现了警告

问题描述 投票:0回答:1

enter image description herehi,我刚刚更新了我的Dropbox api,但我认为这不应该导致这个问题但是在更新之后我正在我的项目中使用xcode 9.2构建它。知道怎么摆脱这个警告吗?

找到了多个名为'count'的方法

请查看方法调用的代码和附加截图。

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [[thumbImagesCollectionArray objectAtIndex:collectionView.tag-1] count];
}
ios objective-c warnings xcode-workspace
1个回答
1
投票

在给[thumbImagesCollectionArray objectAtIndex:collectionView.tag-1]打电话之前,你应该把NSMutableArray投到count

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    [(NSMutableArray *)[thumbImagesCollectionArray objectAtIndex:collectionView.tag-1] count];
}

据我所知,在编译时,调用[thumbImagesCollectionArray objectAtIndex:collectionView.tag-1]时返回的对象类型是未知的。而且它不知道应该在这个对象上调用什么count方法。这就是为什么我们有警告。

要修复它,将对象返回到NSMutableArray,以便编译器知道应该调用什么方法。

© www.soinside.com 2019 - 2024. All rights reserved.