Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
saving a photo to an NSMutableDictionary in iPhone app
I have an app which has a MainViewController (MVC) and a DetailViewController (DVC).
From the MVC I use an NSMutableDictionary to load an image view and a text view in the DVC depending on which image in the MVC is tapped (kind of like a tableview. I also have an empty UIImageView in the DVC.
Inside the DVC I have a button to open the camera. i can take a photo and save it to the app's documents folder and it shows up in the empty UIImageView. However when I return to the MVC and go back to the same called DVC where the photo was displayed it is no longer displayed even though I know it has been saved into the documents. If I tap on a different image in the MVC and open a different DVC grouping I can take a photo but the problem is I don't know how to progressively name the saved images.
What I would like to do is have the photo taken in DVC #1 be saved as image #1 and show up every time I open DVC #1 and then when I open DVC #1 and take a photo it is saved as image #2 and stays displayed in it and so forth and so on. First off is this possible? And admitting that I am rather new to coding and I think here way over my head could someone help me accomplish this.
// Unable to save the image if (error) alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Unable to save image to Documents." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; else // All is well alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Image saved to Documents." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
//this is the view where the photo is shown in the DVC
I have an app which has a MainViewController (MVC) and a DetailViewController (DVC).
From the MVC I use an NSMutableDictionary to load an image view and a text view in the DVC depending on which image in the MVC is tapped (kind of like a tableview. I also have an empty UIImageView in the DVC.
Inside the DVC I have a button to open the camera. i can take a photo and save it to the app's documents folder and it shows up in the empty UIImageView. However when I return to the MVC and go back to the same called DVC where the photo was displayed it is no longer displayed even though I know it has been saved into the documents. If I tap on a different image in the MVC and open a different DVC grouping I can take a photo but the problem is I don't know how to progressively name the saved images.
What I would like to do is have the photo taken in DVC #1 be saved as image #1 and show up every time I open DVC #1 and then when I open DVC #1 and take a photo it is saved as image #2 and stays displayed in it and so forth and so on. First off is this possible? And admitting that I am rather new to coding and I think here way over my head could someone help me accomplish this.
// Unable to save the image if (error) alert = [[UIAlertView alloc] initWithTitle:@\"Error\" message:@\"Unable to save image to Documents.\" delegate:self cancelButtonTitle:@\"Ok\" otherButtonTitles:nil]; else // All is well alert = [[UIAlertView alloc] initWithTitle:@\"Success\" message:@\"Image saved to Documents.\" delegate:self cancelButtonTitle:@\"Ok\" otherButtonTitles:nil];
[alert show];
//this is the view where the photo is shown in the DVC
First off I tried saving as a jpg but it didn't matter.
What I have done is create a variable in my NSDictionary which is the path for the saved photo @"Documents/photoname.jpg". This insures that the name of the photo in each different incarnation of the DVC will save a photo that is specific to that DVC. I then created another UIImageView in the DVC which I then load from the MVC's NSDictionary using the name of the photo I took from that DVC. I know that the photo is being saved into the Documents directory with the desired name because when I use NSLog it shows that that photo name is in the directory. And I know it is being loaded from the MVC into the DVC because of NSLog on both view controllers. However The view doesn't show up in the specified UIImage View. I know that the UIImageView is connected up correctly because if I call another key for the object it works. The only thing I can think is that I am not calling the saved photo correctly from the Documents Directory into the NSMutableDictionary or the photo is not being saved as an image. Is there a way I can check this?
Since most of the images I am calling in the NSMutableDictionary are from the main bundle of the app do I need to do something to put things from the Documents directory into the main bundle or is there a different way to call images saved in the Documents Directory.
First off I tried saving as a jpg but it didn't matter.
What I have done is create a variable in my NSDictionary which is the path for the saved photo @"Documents/photoname.jpg". This insures that the name of the photo in each different incarnation of the DVC will save a photo that is specific to that DVC. I then created another UIImageView in the DVC which I then load from the MVC's NSDictionary using the name of the photo I took from that DVC. I know that the photo is being saved into the Documents directory with the desired name because when I use NSLog it shows that that photo name is in the directory. And I know it is being loaded from the MVC into the DVC because of NSLog on both view controllers. However The view doesn't show up in the specified UIImage View. I know that the UIImageView is connected up correctly because if I call another key for the object it works. The only thing I can think is that I am not calling the saved photo correctly from the Documents Directory into the NSMutableDictionary or the photo is not being saved as an image. Is there a way I can check this?
Since most of the images I am calling in the NSMutableDictionary are from the main bundle of the app do I need to do something to put things from the Documents directory into the main bundle or is there a different way to call images saved in the Documents Directory.
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhat I have done is create a variable in my NSDictionary which is the path for the saved photo @"Documents/photoname.jpg". This insures that the name of the photo in each different incarnation of the DVC will save a photo that is specific to that DVC. I then created another UIImageView in the DVC which I then load from the MVC's NSDictionary using the name of the photo I took from that DVC. I know that the photo is being saved into the Documents directory with the desired name because when I use NSLog it shows that that photo name is in the directory. And I know it is being loaded from the MVC into the DVC because of NSLog on both view controllers. However The view doesn't show up in the specified UIImage View. I know that the UIImageView is connected up correctly because if I call another key for the object it works.
The only thing I can think is that I am not calling the saved photo correctly from the Documents Directory into the NSMutableDictionary or the photo is not being saved as an image. Is there a way I can check this?
Since most of the images I am calling in the NSMutableDictionary are from the main bundle of the app do I need to do something to put things from the Documents directory into the main bundle or is there a different way to call images saved in the Documents Directory.
Here is my added code.
this is put into my MVC's NSMutableDicationary
@"camera image 1.jpg", @"photoImage",
@"Documents/camera image 1.jpg", @"photokey",nil];
This was added to the DVC's ViewDidLoad
photoView2 .image = [[UIImage alloc] init];
self.photoView2.image =[UIImage imageNamed:[(NSMutableDictionary *)myDictionary objectForKey:@"photoImage"]];
and this I put in my DVC's image pickers code
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[(NSMutableDictionary *)myDictionary objectForKey:@"photokey"]];
and ideas are very much appreciated.
One more thing when I take the picture and save it it does show up as a preview and it does day it is saved in the documents directory.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome