In the previous lesson, you added rudimentary synchronization which was done on the main thread. Blocking the main thread in such a way is not recommended. In this lesson you will move the synchronization to a background thread, and add a synchronization observing method to update a progress display.
Synthesize the properties in the implementation and add a release call in the dealloc method. Open the ProgressToolbarViewController by double-clicking ProgressToolbarViewController.xib in the Xcode Resources folder. Since this view will be displayed in a toolbar, you must size it appropriately, and set its background properties:
In the Document window (Command-0), select the View object.
In the Attribute Inspector (Command-1), set the simulated status bar to None.
Set the Background opacity to 0%
Uncheck the Opaque setting.
In the Size Inspector (Command-3), set the width to 232 and the height to 44.
Click and drag a UIProgressView from the Library to the View.
In the Size Inspector (Command-3), set the position of the progress view to 26, 29.
Set the width of the progress view to 186.
In the Attributes Inspector (Command-1), set the style to Bar and the progress to zero.
Click and drag a UILabel from the library to the view.
In the Size Inspector (Command-3), set the position of the label to 14, 5.
Set the size of the label to 210, 16.
In the Attribute Inspector (Command-1), set the text to Sync Progress.
Set the layout alignment to center.
Set the font to Helvetica bold, size 12.
Set the text color to white.
Set the shadow color to RGB: (103, 114, 130), with 100% opacity.
Select the File's Owner in the Document window.
In the Connectors Inspector (Command-2), link the label outlet to the UILabel you created in the last steps.
Link the progress outlet to the UIProgressView you created in the last steps.
Save the XIB file and close Interface Builder.
This view will be added to the RootViewController's toolbar. However, the DataAccess object will also use a reference to it to display the progress of the synchronization. Add the following instance variable:
ProgressToolbarViewController * progressToolbar; |
and add the property to the DataAccess class:
@property (retain, readwrite) IBOutlet ProgressToolbarViewController * progressToolbar; |
Import the ProgressToolbarViewController header and to synthesize the property in the implementation. To actually add the progress view to the toolbar, add the following to the RootViewController's viewDidLoad method:
// Create progress display ProgressToolbarViewController * progress = [[ProgressToolbarViewController alloc] initWithNibName:@"ProgressToolbarViewController" bundle:nil]; // Register the toolbar with the DataAccess [[DataAccess sharedInstance] setProgressToolbar:progress]; // Setup UIBarButtonItems UIBarButtonItem * space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem * progressButtonItem = [[UIBarButtonItem alloc] initWithCustomView:progress.view]; // Put them in the toolbar self.toolbarItems = [NSArray arrayWithObjects:space, progressButtonItem, space, nil]; [space release]; [progressButtonItem release]; |
The RootViewController now has a progress view in its toolbar, even though the toolbar is hidden. In the next section, you will move synchronization to a background thread and display the progress toolbar during the sync.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |