swift - iOS - retain View Controller state after presenting modal on top of it -


so have view controller a, presents view controller b modally. set delegate b when b presented. b has 2 buttons @ top: done , cancel. both call

dismissviewcontrolleranimated(true, completion: nil) 

but done calls delegate method stores information in array in a. works great, except when go b stuff stored array previous done click, , click cancel time instead, array initialized default empty state.

how dismiss b while maintaining existing state of array? thanks.

edit

sorry - realized impossible visualize describing, here gist of code:

class a: uiviewcontroller, bprotocol {      var array: [user] = []      func viewdidload() {      ...     }      func bprotocolfunction(newarray) {         array = newarray     }      func prepareforsegue() {         ...         b.delegate = self     }  }   class b: uiviewcontroller {     var delegate: bprotocol?      // works great, copies new array array in a.  however,     //   if go modal, , click cancel,     //   array reset     func donebuttonclicked() {         delegate.bprotocolfunction(newarray)         dismissviewcontrolleranimated(...)     }      // if user clicks cancel, modal dismissed     //   array reset []     func cancelbuttonclicked() {         dismissviewcontrolleranimated(...)     } } 

so summarize: user goes b. b presented modally. when in b, stuff, click done , delegate method called changes array in a, , modal dismissed. after that, if go b, , click cancel - array reset []. want retain array first done click.

there must error somewhere in code.

judging posted code, there no way array reset 0 since cancelbuttonclicked not fire delegate

my guesses are:

  1. you misplaced action target of cancelbutton donebuttonclicked() function.
  2. somewhere in viewcontroller, reset array other in bprotocolfunction

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -