VCAllSpecImages.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #import "VCAllSpecImages.h"
  2. #import "DetailViewController.h"
  3. #import "SVGKSourceLocalFile.h"
  4. @interface VCAllSpecImages ()
  5. @property(nonatomic,strong) NSString* xcodeVirtualFolderPath;
  6. @property(nonatomic,strong) NSMutableArray* svgFileNames;
  7. @end
  8. @implementation VCAllSpecImages
  9. -(void)viewDidLoad
  10. {
  11. [super viewDidLoad];
  12. if( self.svgFileNames == nil )
  13. {
  14. NSError *error = nil;
  15. self.xcodeVirtualFolderPath = [[[NSBundle mainBundle] resourcePath]
  16. stringByAppendingPathComponent:self.pathInBundleToSVGSpecTestSuiteFolder];
  17. NSArray *xcodeVirtualFolderSVGContents = [[NSFileManager defaultManager]
  18. contentsOfDirectoryAtPath:[self.xcodeVirtualFolderPath stringByAppendingPathComponent:@"svg"] error:&error];
  19. NSMutableArray *svgFileNames = [xcodeVirtualFolderSVGContents mutableCopy];
  20. // Sort by name because by default it's not sorted
  21. [svgFileNames sortUsingSelector:@selector(caseInsensitiveCompare:)];
  22. self.svgFileNames = svgFileNames;
  23. }
  24. }
  25. -(NSArray*) sectionAtIndex:(NSInteger) index
  26. {
  27. return self.svgFileNames;
  28. }
  29. -(NSString*) filenameAtIndexPath:(NSIndexPath*) indexPath
  30. {
  31. NSArray* section = [self sectionAtIndex:indexPath.section];
  32. NSString* item = [section objectAtIndex:indexPath.row];
  33. return item;
  34. }
  35. #pragma mark - UICollectionView
  36. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  37. {
  38. UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  39. NSString* filename = [self filenameAtIndexPath:indexPath];
  40. UILabel* l = (UILabel*) [cell viewWithTag:1];
  41. l.text = filename;
  42. UIImageView* iv = (UIImageView*) [cell viewWithTag:2];
  43. /** Xcode 3, 4, 5 and even version 6 -- all SUCK. "Groups", "Folders", and "Folder References" are all STILL broken by default
  44. Spec adds hundreds of files, and Xcode deletes the folders. So must use folder-references. But Apple folder-references STILL break Apple's UIImage, so we have to specify manual path.
  45. */
  46. NSString* fullPathImageFileName = [[self.xcodeVirtualFolderPath stringByAppendingPathComponent:@"png"] stringByAppendingPathComponent:filename];
  47. UIImage* savedImage = [UIImage imageNamed: [fullPathImageFileName stringByDeletingPathExtension]];
  48. if( savedImage != nil )
  49. {
  50. iv.image = savedImage;
  51. }
  52. else
  53. iv.image = nil;
  54. return cell;
  55. }
  56. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  57. {
  58. return 1;
  59. }
  60. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  61. {
  62. return [self sectionAtIndex:section].count;
  63. }
  64. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66. //SampleFileInfo* item = [self itemAtIndexPath:indexPath];
  67. [self performSegueWithIdentifier:@"ViewSVG" sender:nil];
  68. }
  69. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  70. {
  71. if( [segue.destinationViewController isKindOfClass:[DetailViewController class]])
  72. {
  73. DetailViewController* nextVC = (DetailViewController*) segue.destinationViewController;
  74. NSString* filename = [self filenameAtIndexPath:[self.collectionView indexPathsForSelectedItems][0]];
  75. nextVC.detailItem = [SVGKSourceLocalFile sourceFromFilename:[[self.xcodeVirtualFolderPath stringByAppendingPathComponent:@"svg"] stringByAppendingPathComponent:filename]];
  76. }
  77. }
  78. @end