Loading an image view with saved image in segue - iphone

I am using following code to assign an image to an ImageView
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"imgHand"])
{
RingController *ctrl = segue.destinationViewController ;
ctrl.imgHand.image = [[UIImage alloc] initWithContentsOfFile:self.selectedPath];
}
}
However the imgHand shows black and no image is assigned to it.
Image at this path does exist and have already assigned it to an image in CollectionView
Printing description of self->selectedPath:
/var/mobile/Applications/79092B1E-BE77-4583-A39A-C2D4767ADA12/Documents/myHandImage1.png

Your problem is that your "imgHand" image view property isn't insantiated or fully synthesized in the parent view controller's "prepareForSegue" method. It's a NULL object at that point.
Expose a standalone "UIImage" property from your "RingController" and you can set the image via the parent's "prepareForSegue" method call, then in RingController's "viewDidLoad:" you can set the image view to be the image.

Related

how to populate an array or any object from one view controller to another when we present the view using story board

I have implemented my iphone app using story board
In my app *i need to present a view from one view to another view not the pus*h,
I have created a screen in story board xib for the second view .
i set up the connection for button in the first view to the second view with 'present' not pust.
Now i need to populate an array to the second view which was presented
i tried following ways but not work out
1:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UIButton *)sender
{
//Populate detail to BuyView mail page
if ([segue.id
entifier isEqualToString:#"BuyView"])
{
BuyViewController *destViewController = segue.destinationViewController;
destViewController.itemDetailsArray = [_itemDetailsArray objectAtIndex:sender.tag] ;
}
}
2:
- (IBAction)buyItemClick:(UIButton *)sender
{
BuyViewController *destViewController = [[BuyViewController alloc] init];
destViewController.itemDetailsArray = [_itemDetailsArray objectAtIndex:sender.tag] ;
}
On top of what #rdelmar has stated you are passing an object of which may or may not be an array.
Which in turn would mean
destViewController.itemDetailsArray
Would be pointing to an object which may not be an array.
I think what you want to do is
destViewController.itemDetailsArray = _itemDetailsArray;

Creating an UIImageView on UIButton click

I have a button setup in one class and on clicking it, I am calling a method which is in another class and in that method I have setup code for UIImageView.
the method is getting called, But somehow the ImageView doesnt seems to get created, I dont understand why, And therefore I cannot add any Image to that ImageView.
Here's some code of what I am trying to do:
In my first viewControllerClass I have this method which fires on a button click:
- (IBAction)buttonClicked:(id)sender {
[secondViewController createNewImageView];
}
and then in the second viewController I am calling that createNewImageView method, in which I am creating an ImageView at runtime:
-(void)createNewImageView {
newImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100,100, 100, 100)];
newImageView.backgroundColor = [[UIColor yellowColor] colorWithAlphaComponent:0.4];
[self.otherNewView addSubview:newImageView];
}
But somehow the ImageView is not getting added on my view, Any Ideas why this is happening ?
What am i missing here ..?
Thanks for your time :)
EDIT : The class which holds the button is UIPopOverController.
Have you allocated secondViewController before doing,
[secondViewController createNewImageView];
I think you have not created an object for secondViewController.
So before calling the function create the object for the class.

FPPopover UITableView return value

i don't know if anyone is using this open source library for replacing UIPopovercontroller for an iPhone.
i'm trying to deploy the FPPopover into my project, everything is working like i want, but the problem is that i'm not able to return any value to my ViewController.
i'm trying this in didSelectRowAtIndexPath
myParentViewController *parentController =(myParentViewController*)self.parentViewController;
but the problem is that self.parentViewController is (null)
i have also another problem, how can i dismiss the FPPopoverController from within didSelectRowAtIndexPath.
I dismissed the view by adding a popoverView property to the table view controller that is popping up (in this case ATableViewController), and then assigning the FPPopoverViewController to that property. Like this:
ATableViewController *aTableViewController = [[ATableViewController alloc] init];
FPPopoverController *aPopoverController = [[FPPopoverController alloc] initWithViewController:aTableViewController];
aPopoverController.delegate = aTableViewController;
aTableViewController.popoverView = aPopoverController;
Then in didSelectRowAtIndexPath of aTableViewController you can just call:
[self.popoverView dismissPopoverAnimated:YES];
If you are trying to return values to the "parent"...since the parentViewController property is null here, you can just make your own property for it (let's call it "parentView"). So when setting up the above you would use:
aTableViewController.parentView = self;
Then you can access any of the properties of the parentView and return values from the aTableViewController that popped up. A bit of a workaround, but that's what I did...hope it helps!

perpareForSegue - Passing image name - Blank at First

I have a thumbnail view controller with two thumbnails. Each have an IBAction setting the image name. The next view should display the full image.
The first time I select a button, the new view opens but is completely blank. I go back to the previous screen (navigation controller) and select the button again and the full image screen shows with the correct full image.
Back out, select the second button and the full image of the first button is displayed.
It appears that the full image is off by one iteration.
Below are some code snippets.
thumbnailViewController.M
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
fullImageViewController *targetVC = (fullImageViewController*)segue.destinationViewController;
targetVC.fullImageName = _imageName;
}
- (IBAction)running1 {
_imageName = #"img_running1.png";
}
- (IBAction)running2 {
_imageName = #"img_running2.png";
}
fullImageViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
_fullImage.image = [UIImage imageNamed: _fullImageName];
}
Any suggestions.
I'm guessing that you have both the IBAction and the Segue hooked up to your buttons? If so this is your issue. The segue occurs before the IBAction. The solution is instead of having the button hooked up to the segue have the IBAction perform it.
- (IBAction)running1 {
_imageName = #"img_running1.png";
[self performSegueWithIdentifier:#"yourSegue" sender:self];
}
This will correct the order by giving you control. otherwise I believe its segue then action.

UIImageView weird image property issue

I'm dealing with a super easy task that somehow introducing some difficulties...
All I'm trying to do is to create a view controller and set its UIImageView's image property to some image.
When I try to that, I get nil =\
GenericViewController *genericViewController = [[GenericViewController alloc] init];
UIImage *image = [UIImage imageNamed:#"Camera.png"];
genericViewController.genericImageView.image = image;
NSLog(#"%#", genericViewController.genericImageView.image);
Output: (null)
I imagine genericImageView is set up either in a nib or in the -loadView method. However, at the point in which you're trying to access the image view, the view for the VC hasn't been loaded yet. The quick fix is to call
(void)genericViewController.view;
before accessing genericImageView. This will force the view to load. The "better" approach would be to give genericViewController an image property that you assign to, then in its setter you can say
- (void)setGenericImage:(UIImage *)image {
if (_genericImage != image) {
[_genericImage release];
_genericImage = [image retain];
if ([self isViewLoaded]) {
self.genericImageView.image = image;
}
}
}
and in -viewDidLoad you can say
- (void)viewDidLoad {
[super viewDidLoad];
self.genericImageView.image = self.genericImage;
}
This method, besides being more modular and architecturally-sound, also has the advantage where if the view controller's view is unloaded (say, another view is pushed onto the nav stack and a memory warning comes along), when it gets re-loaded it will still have the image.