If you manually create a parent and child relationship between two view controllers, the child view controller might not have a navigation bar in this case. So you might be wondered why the navigation item of the child view controller doesn’t effect on the navigation bar. But you need to understand that the navigation bar on the child view controller is not the child view controller’s navigation bar. Because the child view controller is embedded into the parent view controller. So you need to create a LeftBarButtonItem
on the parent’s navigation bar and customize the button with a target and an action pattern in the parent view controller.
11/16/2016
Wait unitil a loop with asynchronous tasks finishes executing
2:27 PM
dispatch, dispatch_group, GCD, loop, Swift, thread
No comments
A completion Handler in iOS takes a thread to asynchronously get it done. So it means that we can’t know an exact point which the tasks finish. For example, if we use a for loop to execute several tasks in the background, how could we know all the task are done?
In this case you can use dispatch_group.
- Create a dispatch group which graps all the tasks in a for loop with
dispatch_group_create()
. - You point out a position which your code enters the dispatch group with
dispatch_group_enter(groupname)
. - You point out a position which your code leave the dispatch group with
dispatch_group_leave(groupname)
. - Lastly you can get a notification when all the tasks you assigned to a dispatch group is done with
dispatch_group_notify
.
If you want to see a concrete example for it, please refer this.