ios - Change variable of other view controller Swift -


i have modal segue 1 view controller has table view.

when user selects cell in table view, want view controller dismissed , in presenting view controller, variable changed contents of cell selected.

how can change variable in view controller programatically? (without using prepareforsegue method, since not doing segue, dismissing view controller)

this sounds bit of strange pattern (selecting table view moves forward in navigation) can way. create protocol called cellselectnotification needs method identifies selected cell (perhaps takes indexpath, keep implementation simple). make parent view controller conform protocol , give view controller presenting table view reference parent cellselectnotification delegate. when table view has cell selected notify parent of selected index path through delegate method defined, allow view controller dismissed.

this general way of allowing objects should not have references each other communicate - delegate pattern says "i need situation handled, handling delegated receipient - implementation not important caller".

another way via key-value observing or through nsnotification these last 2 bit heavyweight simple notification want in case.


Popular posts from this blog