Duplicated uiview added programmatically

I'm currently making a photo decoration app. The *holderView is the sticker that has been chosen by user. Whenever I try to load a photo from photo library or take a photo and then load back to this page, additional *holderView added programmatically, which is the sticker that I've previously chosen before taking a photo, duplicated sticker appears after that, which is not what I want it to be.

How should I write the code for not letting this happen? Thanks a lot.

- (void)viewWillAppear:(BOOL)animated { UIView *holderView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, _imagePicker.selectedImage.size.width, _imagePicker.selectedImage.size.height)]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:[holderView frame]]; [imageView setImage:_imagePicker.selectedImage]; [holderView addSubview:imageView]; ... }

-------------Problems Reply------------

Your problem seems to be that your using the viewWillAppear method instead of the viewDidLoad. This will cause multiple "imageViews" because your adding a new one every time you hide then show the viewController it's presented in. what you want to do is move the creation of the imageView (if there really is suppose to only be 1) to the viewDidLoad method and make that imageView accessible to the entire class, then in the viewWillApear simply change the image inside the imageView to the newly selected one.

Category:ios Views:0 Time:2012-01-06

Related post

  • draw in a sub view added programmatically? 2010-12-22

    I have a UIScrollView added programmatically to a UIView. I want to draw few images to the UIScrollView itself. I know how to draw in the main view using: [image drawInRect....]; but I just can not understand how to do it inside of a sub view? i fill

  • Accessing controls added programmatically on postback 2009-11-19

    On postback: How can I access ASP.NET controls in my code-behind file, which are added programmatically? I am adding a CheckBox control to a Placeholder control: PlaceHolder.Controls.Add(new CheckBox { ID = "findme" }); Controls added in the ASPX fil

  • how to make a UIView added to UITableViewCell content view fit within its bounds? 2011-06-12

    how to make a UIView added to UITableViewCell content view fit within its bounds? That is, I have created a single NIB file (with 3 labels on it), and want to use this for the display of each cell in a UITableView. I'm adding in the cellForRowAtIndex

  • sync event added programmatically with google calendar in android 2012-01-18

    I am trying to add an event to the android calendar, and I specify that the event will be added to the gmail calendar in order to sync with the Google calendar automatically. The problem is events added programmatically don't sync with Google calenda

  • Event doesn't trigger on an input when its added programmatically using jQuery 2012-01-25

    Hello StackOverflow, I'd like to know if there is way to trigger an event after the control (in this case an input textbox) has been added programmatically using jQuery. What I mean is, I added a row filled with s and inputs to a table using jQUery.a

  • Obtain a reference to a page element that was added programmatically 2012-12-21

    Hi Is there a way for me to know the ObjectID(s) of a any Page Element(s) e.g. a Table that I've just added programmatically using ApplicationClass.UpdatePageContent method? Many thanks, Marco --------------Solutions------------- ObjectIDs (and page

  • Subviews added programmatically to UIView in storyboards does not responds to action 2011-12-30

    I have a scroll view with many elements that I had to build as a separate xib because Storyboards graphic interface was clipping it and made me impossible to work with. The xib is built with interface builder, setting the file's owner graphically to

  • Adding UIView subclass programmatically not drawing itself 2012-02-24

    I don't understand how this works. If I draw a UIView object to my UIViewController .xib file, then my UIView redraws itself. If I add it to the subView like CustomView : UIView in UIViewController's viewDidLoad CustomView *v = [[CustomView alloc] in

  • how to release uiview added as subview in scrollview? 2009-08-29

    i have added a UIViewController's view and a button to scrollview as subview...now how do i release all instance of UIViewController's...here is an attached image in the view every uiview has a button over it for further navigation.... now i want to

  • how to set UIView background programmatically 2009-12-25

    in the interface builder,i can find the background tag,and select the color and the opacity. if I create the UIView programmatically,if I want to change color,I can set the backgroundColor property the question is if I want to change the opactiy,What

  • UIView added with incorrect orientation 2010-04-16

    So I have been working on a problem with UIView on the iPad. Essentially I have a splitview as the root view and I want to overlay my custom image view over top of the splitview (This is because the splitview must be the root view). The problem that

  • UIBarButtonItem icon white when added via IB, black when added programmatically 2010-08-07

    When I add an icon to a UIBarButtonItem via the Interface Builder, the icon is displayed white. When I add the same icon file programmatically to another UIToolbar, the icon is displayed black. Why? UIImage *image = [UIImage imageNamed:@"icon.png"];

  • UIView added to a ScrollView and touchesDidBegin issue 2011-03-22

    Im adding a UIView as a subView to a scrollView. However, I wish to detect touches in the UIView. But i notice that when i do something like this: [self.myScrollView addSubview:myView]; then, the touchesDidBegin method is never called when i touch th

  • Jetty: adding programmatically 2011-04-09

    I have a standalone application with embedded Jetty and Wicket. I'd like to use CDI for injection. So I've found http://docs.jboss.org/weld/reference/latest/en-US/html/environments.html#d0e5286 and now I'm trying to add this programatically, but it's

  • How to transfer touchesEnded to a UIView added by touchesBegan on a different UIView? 2011-06-01

    I'm using the touchesBegan method in my main UIView to create a second UIView and add it as a subView. What I'd like to be able to do is to have the second UIView get the touchesEnded event when I lift my finger up. I don't seem to be able to do this

  • Changing the UIView Orientation Programmatically without shouldAutorotateToInterfaceOrientation 2011-10-19

    I am looking to change the orientation of an UIView without using the shouldAutorotateToInterfaceOrientation method. I would like to know if the is a method I can call that will set the orientation in a similar matter. Can this be done or do I have t

  • Multiple UITextFields added programmatically , only one can be edited 2011-12-02

    I have a problem adding multiple UITextFields in a UIView, they are added correctly but it happens that the user can only edit the first of them ( touching it so the keyboard appears), i have set the delegate to self, and implemented the method textF

  • Objective C - addobserver for UIView adding subviews? 2012-02-02

    Is there an easy way for listening for when a child or subview has been added to a UIView? I've gone through the addobserver options and haven't found an obvious option anyway. There may be another option that would be affected though when content is

  • Custom view not inflating layout when added programmatically 2012-02-16

    I'm trying to add a custom view to a linear layout programmatically. I want the custom view to inflate a layout I've already created. When I create an instance of the custom view and add it, a spot shows up where the view is, but the layout didn't se

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.067 (s). 11 q(s)