ios - UIImagePickerController duplicates content on close -


when bring uiimagepickercontroller , close it, duplicates content in modal window. below before , after pictures:

enter image description here

enter image description here

here's code shows image picker:

-(void) choosephotos {     uiimagepickercontroller *imagepicker = [[uiimagepickercontroller alloc] init];      [imagepicker setdelegate:self];     [imagepicker setallowsediting:yes];     [imagepicker setsourcetype:uiimagepickercontrollersourcetypecamera];      [self presentviewcontroller:imagepicker animated:yes completion:nil]; } 

here's rest of code (if needed):

-(id) init {     self = [super init];      if (self)     {         [self.navigationitem settitle:@"deposit"];          uibarbuttonitem *closebutton = [[uibarbuttonitem alloc] initwithtitle:@"cancel" style:uibarbuttonitemstyledone target:self action:@selector(cancel)];         [self.navigationitem setleftbarbuttonitem:closebutton];          toitems = @[@"account...5544", @"account...5567"];          uitapgesturerecognizer *recognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(hidekeyboard)];         [self.view addgesturerecognizer:recognizer];     }      return self; }  -(void) hidekeyboard {     (uitextfield *field in [scrollview subviews])     {         [field resignfirstresponder];     } }  -(void) cancel {     [self.navigationcontroller dismissviewcontrolleranimated:yes completion:nil]; }  -(nsinteger)numberofcomponentsinpickerview:(uipickerview *)pickerview {     return 1; }  -(nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component {     return [toitems count]; }  -(nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component {     return [toitems objectatindex:row]; }  -(void) viewwillappear:(bool)animated {     [super viewwillappear:yes];      [self.view setbackgroundcolor:[uicolor whitecolor]];      uilabel *tolabel = [[uilabel alloc] initwithframe:cgrectmake(20, 0, 50, 100)];     [tolabel settext:@"to:"];      topicker = [[uipickerview alloc] initwithframe:cgrectmake(130, -30, 220, 100)];     [topicker setdatasource:self];     [topicker setdelegate:self];      uilabel *amountlabel = [[uilabel alloc] initwithframe:cgrectmake(20, 100, 70, 100)];     amountlabel.linebreakmode = nslinebreakbywordwrapping;     amountlabel.numberoflines = 0;     [amountlabel settext:@"check amount:"];      uitextfield *amountfield = [[uitextfield alloc] initwithframe:cgrectmake(130, 100, 270, 100)];     [amountfield setplaceholder:@"enter amount"];     [amountfield setreturnkeytype:uireturnkeydone];     [amountfield setkeyboardtype:uikeyboardtypedecimalpad];      uilabel *imageslabel = [[uilabel alloc] initwithframe:cgrectmake(20, 200, 70, 100)];     imageslabel.linebreakmode = nslinebreakbywordwrapping;     imageslabel.numberoflines = 0;     [imageslabel settext:@"check images:"];      uibutton *imagesbutton = [[uibutton alloc] initwithframe:cgrectmake(120, 200, 244, 99)];     [imagesbutton setbackgroundimage:[uiimage imagenamed:@"photos.png"] forstate:uicontrolstatenormal];     [imagesbutton addtarget:self action:@selector(choosephotos) forcontrolevents:uicontroleventtouchupinside];      cgrect bounds = [[uiscreen mainscreen] bounds];     scrollview = [[uiscrollview alloc] initwithframe:cgrectmake(0, 0, bounds.size.width, bounds.size.height)];     [scrollview setalwaysbouncevertical:yes];     [scrollview setshowsverticalscrollindicator:yes];      [scrollview addsubview:tolabel];     [scrollview addsubview:topicker];     [scrollview addsubview:amountlabel];     [scrollview addsubview:amountfield];     [scrollview addsubview:imageslabel];     [scrollview addsubview:imagesbutton];      [self.view addsubview:scrollview]; } 

your ui elements being added view every time viewwillappear called. called when image picker dismisses , returns view, they're being duplicated. either check see whether ui elements exist before creating them again, or ui setup in viewdidload method run once. try perhaps, using bool property keep track:

-(void) viewwillappear:(bool)animated {    [super viewwillappear:yes];    if (!self.alreadyappeared) {       self.alreadyappeared = yes;       // create labels , buttons   } } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -