I haven't written anything for a long time, so I'll leave a note today.
After all, not fully understand the working mechanism of iOS, hastily use engineering to practiced hand, some relatively simple problems, solve or take some detours.
In my project, there is the code behind the background work, the background work will need to notify the foreground all page refresh, initially I use a custom protocol to deal with, theoretically feasible, I will all need to update the interface to implement the refresh protocol, and then add the interface instance into an array, Iterate through the array when you need to update the interface, notifying you.
Protocol mirefresh{ func Refresh ()}
var list = [Mirefresh] ()//all interfaces
For x in list { X.refresh ()}
Interface Implementation Mirefresh
Class Listcontroller:uitableviewcontroller, mirefresh{ func refresh () {println ("Update")}}
Add itself to the list when the interface starts
Override Func Viewdidload () { super.viewdidload () list.append (self) }
In fact, this method can be implemented refresh, but will cause the list to add duplicate objects, I try to detect whether the list contains the implementation of the Protocal object, but always not its method.
Toss the majority of days, in the group consulting also did not get effective solution, finally through a predecessor, using Notificationcenter to solve, in fact, Notificationcenter is also very simple
Add observer identity to the interface and specify the method to invoke
Func Regrefresh () { nsnotificationcenter.defaultcenter (). Addobserver (Self, selector: "Refresh", Name: "Refresh", Object:nil) }
Called when a notification is required
Func Notifyall () { nsnotificationcenter.defaultcenter (). Postnotificationname ("Refresh", Object:nil) }
Thank you for your help, in some notes, also want to be able to help others.
Ben Five people learn iOS: Notify all UI Updates