Delegates Vs. Notifications in iPhoneOS

前端 未结 7 1888
既然无缘
既然无缘 2020-12-04 06:23

I am trying to call a method in my root view controller from a child view controller such that when I change my options they will automatically update the root view, which w

7条回答
  •  隐瞒了意图╮
    2020-12-04 07:14

    Notifications can make the runtime behavior of your program significantly more complex. Think of it like a goto with multiple destinations. The order of those destinations is not defined. If you ever crash there is little stack trace information.

    There are cases when it makes sense to use notifications--the typical one being to communicate a model change or a global state change to your views. Example, the network is down, the application will resign, etc!

    It is worthwhile to learn the delegate pattern in iOS. Delegates give you complete stack traces when you debug. They result in significantly simpler runtime behavior while still achieving the goal of decoupling your objects.

提交回复
热议问题