Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation LibraryViewController
- @synthesize dataController = _dataController;
- - (id)init{
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- self = [super initWithCollectionViewLayout:layout];
- [self.collectionView setCollectionViewLayout:layout];
- [self.collectionView setBounds:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
- self.dataController = [[LibraryDataController alloc] init];
- [self.collectionView registerClass:[LibraryCell class] forCellWithReuseIdentifier:@"libraryCell"];
- return self;
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [self.navigationController setNavigationBarHidden:YES animated:animated];
- [super viewWillAppear:animated];
- [self.collectionView reloadData];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [self.navigationController setNavigationBarHidden:NO animated:animated];
- [super viewWillDisappear:animated];
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)addPhoto:(NSString *)imagePath day:(NSInteger)day month:(NSInteger)month year:(NSInteger)year{
- [self.dataController addPhoto:imagePath day:day month:month year:year];
- }
- -(NSInteger)dataCount{
- return [self.dataController listCount];
- }
- #pragma mark -
- #pragma mark UICollectionViewDataSource
- -(NSInteger)numberOfSectionsInCollectionView:
- (UICollectionView *)collectionView
- {
- return 1;
- }
- -(NSInteger)collectionView:(UICollectionView *)collectionView
- numberOfItemsInSection:(NSInteger)section
- {
- return [self.dataController listCount];
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- DetailViewController *detailView = [[DetailViewController alloc] init];
- NSLog(@"%d",indexPath.row);
- detailView.photoIndex = indexPath.row;
- [self presentModalViewController:detailView animated:YES];
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView
- layout:(UICollectionViewLayout*)collectionViewLayout
- sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- NSLog(@"SETTING SIZE FOR ITEM AT INDEX %d", indexPath.row);
- return CGSizeMake(80, 120);
- }
- - (UIEdgeInsets)collectionView:
- (UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- return UIEdgeInsetsMake(10, 10, 10, 10);
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
- return 20.0;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
- cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- LibraryCell *myCell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"libraryCell" forIndexPath:indexPath];
- UIImage *image;
- int row = [indexPath row];
- NSString *photoPath = [self.dataController PhotoOrNotesAtIndex:row photoOrNotes:@"photo"];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
- NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
- NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:photoPath]; //add our image to the path
- image = [UIImage imageWithContentsOfFile:fullPath];
- if(image)
- NSLog(@"success");
- myCell.imageView.image = nil;
- myCell.imageView.image = image;
- return myCell;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement