我创建了一个带有两个集合视图的tabbar应用程序。我成功地有2个标签栏使用集合视图,但他们都从相同的图像文件夹接收数据 - 拇指&完整。所以,这两个标签上的图像目前是相同的。收藏视图 - 从不同文件夹接收图像 - 如何?
我希望找出最好的办法是从不同的文件夹中获取不同的图像,所以它们不一样?
如果您需要更多信息,请告诉我。
NSString *kDetailedViewControllerID = @"DetailView";
NSString *kCellID = @"cellID";
@implementation ViewController
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
return 29;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
NSString *imageToLoad = [NSString stringWithFormat:@"%d.JPG", indexPath.row];
cell.image.image = [UIImage imageNamed:imageToLoad];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"])
{
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
// load the image, to prevent it from being cached we use 'initWithContentsOfFile'
NSString *imageNameToLoad = [NSString stringWithFormat:@"%d_full", selectedIndexPath.row];
NSString *pathToImage = [[NSBundle mainBundle] pathForResource:imageNameToLoad ofType:@"JPG"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.image = image;
}
}
@end
显示您正在执行的操作以获取图像并将图像保存到2个文件夹的代码。为什么你不能只为图像设置适当的路径? – Wain
代码被编辑到问题中,我不确定是否需要创建新类或者是否可以复制代码并相应地更改字符串。 – aaip