No. 07 Chapter Uitabbarcontroller & Uipickerview

Source: Internet
Author: User

What is a nib file? A series of objects that are serialized to a file, including controller, view, control, export, action.   How can I associate a controller with a nib file? Initwithnibname method The file ' s owner type of the nib file must be specified as the controller type, and the controller's view output must be associated to the view  of the nib when the controller is created. Automatically create a xib file, what's inside? In fact, for two things, the file ' s owner type of the specified nib file must be specified as the controller type; The controller's view output is associated to the view  of the nib. Apple comes with a few controller classes uiviewcontroller  ignoring the diagram, only a view output.    attributes are: Title: Name nib name:nib file name layout: Whether full screen, will hide tabbar whether hide bottom bar, whether resize view   There is a uitabbar view at the bottom of the Uitabbarcontroller and then two Uiviewcontroller, each containing a uitabbaritem (the view can have child views, And Uiviewcontroller has a Tabbaritem attribute that points to a uitabbaritem)?    uitabbaritembadge: Small icon in the upper right corner, Similar to the number of messages received identifier: predefined some types title: Name Image: Images   Add the specific type of controller in the new Label Settings tab, set its associated xib file (equivalent to Initwithnibname) Modifies the title,image  1 of the Uitabbaritem associated with the controller. Create a tab bar Application framework 1) Empty Application template 2) Create a new empty tabbarcontroller.xib, drag from the object library into an off-the-shelf tab Bar controller  This xib file is loaded into memory, How do I get to a ready-made Uitabbarcontroller object? There are two ways: 1) Traditional, output port a. To define a class of files owner for this xib file (this works with the Appdelegate Class), then you need to modify the files own of the Xib file.Type of ER b. In appdelegate, define outlet to point to the Tabbarcontroller in this xib file so when the loadnibnamed file is loaded into memory using the method Xib, the previously defined export has pointed to the Tabbarcontrolle in the file R   2) The Nsarray returned directly using the Loadnibnamed method

nsarray* arrays = [[NSBundle mainbundle] loadnibnamed:@ "Tabbarcontroller" owner:self Options:nil];

for (ID obj in arrays)

{

if ([obj Ismemberofclass:[uitabbarcontroller class]] = = YES) {

Self.window.rootViewController = obj;

Break

}

}

(General: Viewcontroller is a xib file Owner,xib file that has a Uiview,viewcontroller view outlet pointing to this view, using the Initwithnib method, Initializes the Viewcontroller through the Xib file. But for this kind of encapsulation, the top-level object is a controller's tabbarviewcontroller.xib, directly using the loadnibnamed, you can get to serialize to the Xib file controller object. )

Notice the difference between loadnibnamed and initwithnib

2. Modify the Tabbarcontroller.xib file to correct the type and Xib file name of each viewcontroller on the corresponding tabbar. 3. Add icon to modify the Image property of Bartabitem 4. Picker by default, the picker displays a list of text, but they can also display images 5. Delegates and data source controllers are picker delegates and data sources 6. New Biddatepickerviewcontroller inherits from Uiviewcontroller, automatically creates the corresponding Xib file New Biddoublecomponentviewcontroller New Biddependentcomponentviewcontroller new Bidcustomviewviewcontroller Implement date picker Uidatepicker drag control to controller, correlate output setting time:

NSDate *now = [NSDate Date];

[Self.datepicker Setdate:now];

Get Time:

NSDate *select = [Self.datepicker Date];

7. Implement a single component picker Uipickerview drag controls to the controller, correlate outputs, set up delegates and data source controllers to implement picker data sources and delegates

#pragma mark-

#pragma mark Picker Data Source Methods

-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview

{

return 1;

}

-(Nsinteger) Pickerview: (Uipickerview *) Pickerview

Numberofrowsincomponent: (Nsinteger) component

{

return [self.pickercontents Count];

}

#pragma mark-

#pragma mark Picker Delegate Methods

-(nsstring*) Pickerview: (Uipickerview *) Pickerview

Titleforrow: (Nsinteger) row

Forcomponent: (Nsinteger) component

{

return [self.pickercontents Objectatindex:row];

}

Get picker currently checked-(Nsinteger) Selectedrowincomponent: (Nsinteger) component8. Implement the multi-component picker, just modify the data source and delegate methods, support multiple components 9. Implement a dependent component to read data from a property list through the data source and delegate, build two components of the picker through the delegate method, update the right wheel data when the user option has an item on the left.

@property (Strong, nonatomic) Nsdictionary *datadic; All data

@property (Strong, nonatomic) Nsarray *states; Cur states

@property (Strong, nonatomic) Nsarray *codes; Cur codes

-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (Nsinteger) component

{

if (component = = Kstateindex) {

Self.codes = [Self.datadic Valueforkey:self.states[row]];

Reload

[Self.dependentpicker Reloadcomponent:kcodeindex];

[Self.dependentpicker selectrow:0 Incomponent:kcodeindex Animated:yes];

}

}

Create A game use Uipickerview support Picture Picker

You need to uncheck the checkbox labeled User Interaction Enabled within

The viewsettings so, the user can ' t manually change the dial and cheat.

  All fonts supported by the print device for (NSString *family in [uifont familynames]) {    NSLog (@ "%@", family);    For (NSString *font in [uifont fontnamesforfamilyname:family]) {        NSLog (@ "\t%@", font); nbsp  }}  uiimage *image = [uiimage imagenamed:@ "Seven"]; -(UIView *) Pickerview: ( Uipickerview *) Pickerviewviewforrow: (Nsinteger) Rowforcomponent: (Nsinteger) component Reusingview: (UIView *) view{     UIImage *image = self.images[row];    Uiimageview *imageview = [[Uiimageview alloc] Initwithimage: image];    return ImageView;}   Implementing different delegates allows the picker to support different types, strings or pictures
    • pickerView:titleForRow:forComponent:
    • pickerView:attributedTitleForRow:forComponent:
    • PickerView:viewForRow:forComponent:reusingView:   srandom ( time ( NULL ));  //random number seed
      Id d = random ();    random numbers, which generate random numbers each time, are different. The meaning of Time (NULL) is to generate the current times. The time () function records the exact times, and the current time is obtained only if you add null to it.   Play Music systemsoundid winsoundid; -(void) playwinsound{if (Winsoundid = = 0) {Nsurl *soundurl = [NSBundle Mainbundle] urlforresource:@ "Win" withextension:@ "wav"]; Audioservicescreatesystemsoundid ((__bridge cfurlref) soundurl,&winsoundid);} Audioservicesplaysystemsound (winsoundid); self.winLabel.text = @ "winning!"; [Self performselector: @selector (Showbutton) withobject:nilafterdelay:1.5];}   need to join the audio Toolbox Framework
Summary: Uitabbarcontroller, an already packaged controller, in IB, you can drag directly from the object library into the Xib file through the Loadnibnamed method, you can load it into memory as the application delegate's root view controller, To manage Baritems

No. 07 Chapter Uitabbarcontroller & Uipickerview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.