objective c - Getting access to objects in other parts of the object graph in iOS -


i'm using ios problem.

i have following class structure:

  1. schedulevc (with uicollectionview ) owns
    1. schedulecell (uicollectionviewcell) owns
      1. scheduledaytvc (uitableviewcontroller) owns
        1. scheduledaycell (uitableviewcell) owns
        2. orderdetailview ( view , subview of contentview)

there action in 5( orderdetailview ) needs call 1( schedulevc ). there 1 schedulevc quick , dirty solution create singleton class gets me quick access.

is best way solve this? didn't think passing down pointer of 1 5 clean.

i looked @ kvo , seemed needed reference both observer , 'being observed' objects don't have anywhere.

edit: top level vc owns uicollectionview has layout similar passbook or reminders. on each cell there tableview it's own controller. each uitableviewcell in tableview has view( 5 ) added it's contentview. view has button when pressed needs contact 1.

what need call? method perform business logic or update ui?

  1. in first case (business logic), better create separate class (not view controller) , make singleton can invoked anywhere without keeping reference it. singleton class can have man observers or alternatively use nsnotificationcenter (see below).

  2. in second case, should think using nsnotificationcenter. triggering nsnotification let observers know (schedulevc should observer) of interest happened , update ui accordingly. pattern can used if have singleton class, can trigger nsnotification when parts of ui need updated.

in case you'll end nicely decoupled architecture doesn't depend on ui/vc structure.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -