Saturday 24 July 2010

Tab Bars and Pickers

(Pickerview) or just a picker are the controls with the dials that spin. Pickers are more complex than other iPhone controls.
Pickers can be configured to display one dial or many, by default pickers display text, but many can also be made to display images.
Date picker is the easiest type of picker to implement.


Picker has very few attributes that can be configured from within the interface builder. Date picker is the only one that can be  grabbed from the interface builder. 


A picker needs to be provided with both a picker delegate and a picker data source. The picker defers several jobs to its delegate. The most important of these is the task of determining what to actually draw for each of the rows in each of its components.


The picker asks the delegate for either a string or a view that will be drawn at a given spot or a given component. The picker gets its data from the delegate. In additon to the delegate, a data source is required.  The data source tells the picker how many components it will be working with and how many rows make up each component.


Its very common for the data source and the delegate to be the same object and just as common for that object to be the view controller for the picker's endorsing view.


The data source isn't actually an object designed to hold data.


Root controller to manage swapping of applications other views. Tab bars use icons to represent each of the tabs. 24 x 24 pixel .png pics need to be added to the resources folder.
The root controller controls the very first view that the user will see when your program runs.
'Badge' in the 'Tab bar item' can be used to put a red icon onto a tab bar item, similar to red number placed on mail icon.
For tab bar controller first single click the first tab and use the atttributes inspector to specify nib name for that tab's associated view controller. Then open the identity inspector and change the underlying class of the view controller associated with the tab.
Click the tab again, instead of the view controller gave the tab bar item a title icon.










Root controller to manage the swapping of application's other views.
Tab bars use icons to represent each of the tabs. 24 x 24 pixel .png pics need to be added to the resources folder.


The root controller controls the very first view that the user will see when your program runs.


'Badge' in the 'Tab Bar Item' can be used to put a red icon onto a tab bar item, similar to red number placed on email icon.
For tab bar controller first single check the first tab and use the attributed inspector to specify a nib name for that tab's associated view controller. Then open the identity inspector and changed the underlying class of the view controller associated with the tab.
Click tab again, instead of the view controller gave the tab item a title and icon.


To implement the date picker a single outlet and a single action is required. The outlet will be used to grab the value from the date picker. The action will be triggered by a button and will throw up an alert to show the date value pulled from the picker.  









Date picker is relatively easy, creating a picker that holds values requires NSArray, as pickers don't hold values themselves. Instead they call methods on their data source and delegates to get the data they need to display. The picker doesn't care where the underlying data is. It asks for the data when it needs it, and the data source and delegate work together to supply that data. As a result, the data could be coming from a static list, or could be loaded from a file or URL, or even made up or calculated on the fly.


controller.h class can act as both the data source and delegate for it's picker. Unlike a date picker, a regular picker cannot tell us what data it holds, because it doesn't maintain the data. It hands the job off to the data source and the delegate. Instead, we have to ask the picker which now is selected and grab the corresponding data from our pickerDataArray.


Using NSInteger as opposed to int or long means that the compiler automatically chooses whichever size is best for the platforms on which the code is being compiled. It will create a 32 bit processor and a longer 64 bit long when compiling for a 64 bit architecture.


Usually data will come from a property file in projects resources folder. Any line of code that begins with #pragma is technically a compiler directive.  







For multi component pickers defining 2 constants will represent 2 components.
Components are assigned numbers, with the left most component being assigned zero and increasing by one each move to the right.  




No comments:

Post a Comment

Search This Blog