【发布时间】:2015-07-24 15:45:15
【问题描述】:
我正在使用这个示例搜索 UICollectionView:https://github.com/ihomam/CollectionViewWithSearchBar/blob/master/collevtionViewWithSearchBar/CollectionViewController.m
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
// Configure the cell
if (self.searchBarActive) {
cell.laName.text = self.dataSourceForSearchResult[indexPath.row];
} else {
cell.laName.text = self.dataSource[indexPath.row];
}
return cell;
}
...只有我的应用程序设置略有不同:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
PlaceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
Place *p = [_entries objectAtIndex:indexPath.item];
if (self.searchBarActive) {
cell.placeName.text = self.dataSourceForSearchResult[indexPath.item];
} else {
cell.placeName.text = p.PName;
cell.placeImg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:p.PImage]]];
}
return cell;
}
因此,如果我按原样运行它,那么 self.dataSourceForSearchResult[indexpath.item] 将返回所有内容,并且我收到一个错误,因为它没有返回字符串...
'Can't use in/contains operator with collection <Place: 0x17d8ad70> (not a collection)'
但我想要它做的是搜索 p.PName 结果。比如:
self.dataSourceForSearchResult[p.PName indexpath.item]
【问题讨论】:
-
你试过了吗:shouldChangeTextInRange:(NSRange)range replacementText:(NSString * _Nonnull)text
-
不确定您的意思...您能否详细说明或给我一个示例链接?
标签: ios xcode6 uicollectionview uisearchcontroller