Parse.com image gallery open image detail view - ios

I haven't been programming for very long and I am trying to create a simple image gallery using Parse.com, I have followed this tutorial https://www.parse.com/tutorials/saving-images but using storyboards instead of nibs.
I managed to got most of it working but I'm stuck at the last hurdle, when it comes to opening the selected image full size in a new view.
Following other answers given around the web I have tried to pass the image to the detail view in - (void)prepareForSegue: but I'm still having no luck.
My code in ViewController.h currently looks like this
- (void)buttonTouched:(id)sender {
PFObject *theObject = (PFObject *)[allImages objectAtIndex:[sender tag]];
PFFile *theImage = [theObject objectForKey:#"imageFile"];
NSData *imageData;
imageData = [theImage getData];
selectedPhoto = [UIImage imageWithData:imageData];
[self performSegueWithIdentifier:#"goGo" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:#"goGo"]) {
PhotoDetailViewController *pdvc = [[PhotoDetailViewController alloc] init];
pdvc.selectedImage = selectedPhoto;
}
}
and in DetailViewController.h
- (void)setDetailImage {
self.photoImageView.image = selectedImage;
}
When it comes to loading the image the view opens blank, any help on this would be a massive help. If it makes it easier I can upload the project.
Thanks in advance,
Chris

Your actual prepareForSegue statements does nothing : you're initializing selectedImage to a totally new PhotoDetailViewController but not the one which will be presenting.
Try to replace
PhotoDetailViewController *pdvc = [[PhotoDetailViewController alloc] init];
by
PhotoDetailViewController *pdvc = (PhotoDetailViewController *)segue.destinationController;

Related

UIImage to Button Method - pointer incompatibility error

I have a UIImage called myImage which I would like to show when this is called:
JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
initWithImageInfo:
mode:JTSImageViewControllerMode_Image
backgroundStyle:JTSImageViewControllerBackgroundStyle_ScaledDimmedBlurred];
I assume myImage would need to go after initWithImageInfo:, right? How do I do this?
I tried initWithImageInfo:myImage but this does not work.
This is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
myImage = [self getMyImageWithSize:(CGSizeMake)(100,100)];
[self.imageButton addTarget:self action:#selector(bigButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)bigButtonTapped:(id)sender {
// Create image info
JTSImageInfo *imageInfo = [[JTSImageInfo alloc] init];
imageInfo.image = [self.imageButton backgroundImageForState:UIControlStateNormal];
imageInfo.referenceRect = self.imageButton.frame;
imageInfo.referenceView = self.imageButton.superview;
// Setup view controller
JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
initWithImageInfo:??????
mode:JTSImageViewControllerMode_Image
backgroundStyle:JTSImageViewControllerBackgroundStyle_ScaledDimmedBlurred];
// Present the view controller.
[imageViewer showFromViewController:self transition:JTSImageViewControllerTransition_FromOriginalPosition];
}
I apologise if this is a stupid question but I've tried Googling for this issue and I can't seem to find anything relatable. Any help would be much appreciated, thanks!
Looking at his sample app is very useful:
https://github.com/jaredsinclair/JTSImageViewController/blob/a02ee23381bed69c995378fd4db400717ebf3fb1/Sample%20App/JTSImageVC/JTSImageVC/JTSViewController.m#L33-L45

Passing a UIImage from a viewcontroller to another

I want to pass a UIImage from a View Controller to another one, but it doesn't work. I actually get (null) if I log the UIImage Value in the second View Controller.
The Image File comes from parse.com. And it works absolutely fine in the first view controller. But as soon as I pass it to the second view controller, the image won't work there.
Here's the code:
My prepareForSegue in the .m file of the firstViewController (BookListTableViewController)
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"ShowBookDetailSegue"]) {
NSIndexPath *indexPath = [self.bookListTableView indexPathForSelectedRow];
ParseBookDetailTableViewController *pbdtvc = segue.destinationViewController;
PFObject *tempObject = [totalStrings objectAtIndex:indexPath.row];
PFFile *eventImage = [tempObject objectForKey:#"bookImage"];
if(eventImage != NULL)
{
[eventImage getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error)
{
UIImage *thumbnailImage = [UIImage imageWithData:imageData];
pbdtvc.bookImageDetail = thumbnailImage;
}];
}
my .h file of the secondViewController (ParseBookDetailViewController)
#property (strong, nonatomic) UIImage* bookImageDetail;
#property (strong, nonatomic) IBOutlet UIImageView *bookImageDetailView;
viewDidLoad of my .m file of the secondViewController (ParseBookDetailViewController)
NSLog(#"%#",bookImageDetail);
[bookImageDetailView setImage:bookImageDetail];
As I said: in the original View Controller the Image is correct. I can log it and even set it there to an ImageView. But in the second view controller there is (null).
Glad for help, thanks..
EDIT:
This is the code from my cellForRowAtIndexPath.
PFObject *tempObject = [totalStrings objectAtIndex:indexPath.row];
//cell.textLabel.text = [tempObject objectForKey:#"bookTitle"];
cell.titleTextField.text = [tempObject objectForKey:#"bookTitle"];
cell.bookAutor1Label.text = [tempObject objectForKey:#"bookAutor1"];
cell.isbnLabel.text = [tempObject objectForKey:#"bookISBN"];
cell.statusLabel.text = [tempObject objectForKey:#"bookStatus"];
cell.yearLabel.text = [tempObject objectForKey:#"BookDate"];
if ([cell.statusLabel.text isEqualToString:#"nicht verfügbar"]) {
cell.statusLabel.tintColor = [UIColor redColor];
cell.dotImageIcon.image = [UIImage imageNamed:#"dot_red.png"];
}else if ([cell.statusLabel.text isEqualToString:#"verfügbar"]){
cell.statusLabel.tintColor = [UIColor greenColor];
cell.dotImageIcon.image = [UIImage imageNamed:#"dot_green.png"];
}
PFFile *eventImage = [tempObject objectForKey:#"bookImage"];
if(eventImage != NULL)
{
[eventImage getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error)
{
UIImage *thumbnailImage = [UIImage imageWithData:imageData];
prepareForSegueImage = thumbnailImage;
[cell.bookImageView setImage:thumbnailImage];
}];
}
At the bottom I have set the Image (that works) in a new property (prepareForSegueImage). NOW its loaded.
And now I've tried to pass only the prepareForSegueImage to the new view controller, but it actually doesn't pass the one from the cell, it passes the last one loaded in the whole table view from the first view controller.
I'm guessing:
[eventImage getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error)
{
UIImage *thumbnailImage = [UIImage imageWithData:imageData];
pbdtvc.bookImageDetail = thumbnailImage;
}];
is an asynchronous request happening in the background, that will take some time to return. But your code is expecting it to happen instantly.
Load the image first and call the segue in the completion block,
EDIT
If it works in the first viewController (meaning you have the image) why are you requesting it again? why not simply pass the image you already have?
EDIT 2:
As explained in my comment, your variable is being overwritten each time the cellForRowAtindexPath is called. You could either wrap that code in an if statement, checking for an index or a certain image etc. or you can use the below code to get a specific cell and pull the image form that.
[tblView cellForRowAtIndexPath: [NSIndexPath indexPathForRow:2 inSection:0]];
If you have the image downloaded and have a relatively easy means of getting a reference to it you should not be downloading it again. This could cost the user on a 3G data plan as well as waste resources.
This happens because you are using the getDataInBackgroundWithBlock, which is an asynchronous call. As this happens in a background thread, it is probably not finished when you segue to the other viewcontroller.
You said it works fine in the first controller. I assume this means you have already downloaded the image. Put that in a property instead, and send this property to the next controller.

Write data to plist while running app and read them to UITable

I want to store the data to plist for the UITable, but so far I am able to read them from plist if they are written there already.I want to write the data while running the app.
Here's the method that saves data to cell in UITableView
-(IBAction)saveAction:(id)sender
{
Tricks *trick = [[Tricks alloc]init];
trick.trickName = self.trickLabel.text;
//trick.trickPhoto = self.ImagePhoto.image;
[[Tricks trickList]insertObject:trick atIndex:0];
[self.navigationController popViewControllerAnimated:YES];
}
In detailViewController I can take photo and drop pin on Map.
Photo,pin and text for cell are stored in subclass of NSObject.
loading detailViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"detailTrick"]){
NSIndexPath *indexPath = nil;
indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
Tricks *trick = [[Tricks trickList] objectAtIndex:indexPath.row];
detailViewController.fileText = trick.trickName;
detailViewController.pinMKPoint = trick.pinNotation;
}
detailViewController.trick = trick;
}
}
Code for wiring to plist
NSString *trickList = [[NSBundle mainBundle]pathForResource:#"trickList" ofType:#"plist"];
_trick = [[NSMutableDictionary alloc]initWithContentsOfFile:trickList];
_trickPhotos = [[_trick objectForKey:#"trickPhotos"]objectAtIndex:0];
_trickNames = [[_trick objectForKey:#"trickNames"]objectAtIndex:0];
_mapAnnotations = [[_trick objectForKey:#"pinKit"]objectAtIndex:0];
I want to write all the data in plist and read them at launch of app.
Thanks for advices.
You have clearly seen NSDictionary's -initWithContentsOfFile: method. Have you looked at -writeToFile:atomically: as well? That seems to be the behavior you are looking for. If you need something more specific please update your question to ask for more specific assistance.

Parse data image shows in iOS simulator but not in device

I'm using a collection view controller to show thumbnails. Click on the thumbnail and a segue opens to the full image modally. It works fine on the simulator, but not on my iphone or ipad. The full image is blank. The "comment" shows up in all devices.
Here's the segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showBandPhoto"]) {
NSArray *indexPaths = [self.collectionView indexPathsForSelectedItems];
BDBPhotoViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [indexPaths objectAtIndex:0];
PFObject *tempObject = [imageObjectsArray objectAtIndex:indexPath.row];
PFFile *imageFile = [tempObject objectForKey:#"image"];
NSData *imageData = [imageFile getData];
UIImage *image = [UIImage imageWithData:imageData];
destViewController.bandImageName = image;
NSLog(#"image is %#", image);
NSString *commentGet = [tempObject objectForKey:#"comment"];
destViewController.comment = commentGet;
Here's the code for the photo controller viewDidLoad:
self.photoImageView.image = bandImageName;
self.commentLabel.text = comment;
Instead of using UIImageView, try using a PFImageView. This subclass makes it much easier for loading image data directly from Parse.
I'm not sure why this worked, but I moved the retrieval from Parse to viewDidLoad and created the image array there. When the segue is called it gets the image from the array, rather than having to query Parse.
For me the problem was that I added extension in image naming. The simulator could read the image but not the device. when I removed extension it worked.
Furthermore, as explained in this post:
images in iphone app appear in simulator but not when compiled to device
Mac file system is case-insensitive and iOS file system is case sensitive. Your problem is maybe juste due to image naming.

Having trouble passing NSString from plist to ImageView

I'm currently using a plist to populate my table view rows(i.e. Name, Description and Image). When the user selects a row, a new controller is pushed up with an imageView presenting the rows image in full screen.
The problem that I'm facing is, passing the string to the new viewController's imageView.
All the NSLog's return the correct information, except that when it logs the UIImageView, it returns null then. Am I not connecting it correctly? The row doesn't display any image until it's selected (essentially the row is acting, similar to a thumbnail).
Any help would be greatly appreciated thank you!!!
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *childDictionary = [mainChildren objectAtIndex:indexPath.row];
//Image Name NSString from plist
childImage = [childDictionary objectForKey:#"Child Image"];
if ([childDictionary objectForKey:#"Child Image"] == nil) {
NSLog(#"No Image String Found.");
}
else {
NSLog(#"Image String Found. Image Name is: %#", childImage);
UIImage *myImage = [UIImage imageNamed:childImage];
NSLog(#"Image Found. Image is: %#", myImage);
UIImageView *childImageView = [childImageView setImage:myImage];
NSLog(#"ImageView Found. ImageView is: %#", childImageView);
FullscreenImageViewController *imgViewer = [[FullscreenImageViewController alloc] init];
imgViewer.fullScreenImageView = childImageView;
[self presentViewController:imgViewer animated:YES completion:nil];
}
}
When you instantiate a new UIImageView, it should be [[UIImageView alloc] initWithImage:image].
Or since your full screen image controller has property of image view, e.g. fullScreenImageView, you can just set the image of the property directly with a UIImage instance.

Resources