iOS Development--ui Advanced (eight) Pickerview simple to use, through the storyboard load controller, register the interface, create a controller through XIB, the controller's view creation, the basic use of the navigation controller

Source: Internet
Author: User

First, Pickerview simple use

1.UIPickerViewDataSource

These two methods must implement the

// returns how many columns -(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview; // return to component number of lines -(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (Nsinteger) Component

2.UIPickerViewDelegate

Common methods

//returns how wide column component-(CGFloat) Pickerview: (Uipickerview *) Pickerview widthforcomponent: (nsinteger) component//returns how high column component-(CGFloat) Pickerview: (Uipickerview *) Pickerview rowheightforcomponent: (nsinteger) component//return to Column component row heading-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (nsinteger) component//nsattributedstring: Rich Text, can describe the appearance of text properties, colors, fonts, shadows, hollow, graphic mixed-(Nsattributedstring *) Pickerview: (Uipickerview *) Pickerview Attributedtitleforrow: (nsinteger) Row forcomponent: (nsinteger) component//return to Column component row view Control-(UIView *) Pickerview: (Uipickerview *) Pickerview Viewforrow: (nsinteger) Row forcomponent: (Nsinteger) component Reusingview: (UIView *) View//called when the user selects a row//When you check the row of row component column, call//can monitor Pickerview scrolling- (void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (Nsinteger) component

Second, the registration interface

1.UITextFieldDelegate

There are times when you want to intercept user input

text box content can only be displayed by Pickerview wheel selection

So just implement the following proxy method.

-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *)string{    return  NO;}

Uitextfielddelegate also has two common methods

// allow editing to start // allow edit text box -(BOOL) textfieldshouldbeginediting: (Uitextfield *) TextField//  Allow text box to end edit -(BOOL) textfieldshouldendediting: (Uitextfield *) TextField

2. Customizing the keyboard
The keyboard is determined by the text box Inputview property

3.KVC Bottom-level implementation

//Setvaluesforkeyswithdictionary Bottom -level implementation//using KVC dictionary to model,[flag setvaluesforkeyswithdictionary:dict]; //1. Traverse all keys in the dictionary[Dict enumeratekeysandobjectsusingblock:^ (IDKeyIDobj, BOOL *stop) {        //2. Assign values to the properties of the model, using KVC, the key in the dictionary is used as the model's property name, and the values in the dictionary are passed to the properties of the model.[flag setvalue:obj Forkey:key]; //Name-icon//KeyPath: Attribute names in a model//the value of the property//[flag setvalue:dict[@ "name"] forkey:@ "name"];//[flag setvalue:dict[@ "icon"] forkey:@ "icon"];    }];//Setvalue:forkey: Bottom -level implementation//Assigning a value to the Icon property in a model//[flag setvalue:dict[@ "icon"] forkey:@ "icon"];//1. First go to find the model has wood SetIcon: method, direct Call SetIcon: method, [Flag seticon:dict[@ "icon"]//2. Then look for the model has no icon attribute name, if any, directly assign the value of icon = dict[@ "icon"]//3. Then find the _icon attribute name in the model, and if so, directly assign _icon = dict[@ "icon"]//4. Not found, direct error, Setvalue:forundefinedkey:

4.UIDatePicker Custom Birthday Keyboard

//Custom Birthday Keyboard- (void) setup{//Create a UidatepickerUidatepicker *datepicker =[[Uidatepicker alloc] init]; //set up a date modelDatepicker.datepickermode =uidatepickermodedate; //Setup area, zh: ChinaDatepicker.locale = [Nslocale localewithlocaleidentifier:@"ZH"]; //Monitor the selected date of the Uidatepicker[DatePicker addtarget:self Action: @selector (Datechange:) forcontrolevents:uicontroleventvaluechanged]; Self.inputview=DatePicker;}//called when a date is selected- (void) Datechange: (Uidatepicker *) datepicker{//NSLog (@ "%@", datepicker.date); //Gets the date displayed on the text box//date format string ObjectNSDateFormatter *fmt =[[NSDateFormatter alloc] init]; //Set Format 1988-01-01Fmt.dateformat =@"YYYY-MM-DD"; Self.text=[FMT stringFromDate:datePicker.date]; }

Three, load the controller through the storyboard
 //uistoryboard: Loading storyboard files for you//Load the storyboard file//name:storyboard file name, no suffix name requiredUistoryboard *storyboard = [Uistoryboard storyboardwithname:@"Main"Bundle:nil]; //Create the controller described by the storyboard//Instantiateinitialviewcontroller help you load the controller that the arrow points toUiviewcontroller *VC =[Storyboard Instantiateinitialviewcontroller]; //Create a controller that storyboard describes based on an identifier//Uiviewcontroller *VC = [Storyboard instantiateviewcontrollerwithidentifier:@ "org"];

Iv. creating a controller through Xib

1. Create a controller by Xib reason:
is to describe the controller's view through Xib.

2. How to create a controller from Xib

1) Let xib with the controller, set the Xib file owner is the controller, this time Xib described the controller

2) Connect, tell the controller which view is in the description


V. View creation of the controller

1.loadView

When to call: when using the controller's view for the first time, it will be called

Function: load the controller's view, customize the controller's view

Attention:

1) As long as you rewrite Loadview, you must manually create the controller's view

2) You cannot call Self.view until you assign a value to _view;


2.loadView Loading process


3.xib Load Controller's view

Init Bottom calls Initwithnibname:bundle:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; //Create a window's root controller based on Xib//Init Bottom calls Initwithnibname:bundle:Xmgviewcontroller *VC =[[Xmgviewcontroller alloc] Initwithnibname:nil Bundle:nil]; //Create a view of the Xmgviewcontroller controller via Xib//1. Determine if the nibname has a value, if there is a value, it will load Nibname specified xib//2. If Nibname is empty, it will go first to find out if there is no xmgview.xib, if any, go to load//3. If there is no xmgview.xib, the xib:XMGViewController.xib with the same name as the root class will be loaded.//4. If not found, create an empty viewSelf.window.rootViewController=VC;        [Self.window makekeyandvisible]; returnYES;}

4. View delay loading of the controller

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; //creating a controller does not create a view for the controller, provided the parent class is UiviewcontrollerViewcontroller *VC =[[Viewcontroller alloc] init]; Vc.view.backgroundColor= [Uicolor Redcolor];//the controller is here to use (load) view//setting the root controller of a windowSelf.window.rootViewController =VC; //display window, get the controller view added to the window to display[Self.window makekeyandvisible]; returnYES;}

is actually a lazy load

-(UIView *) view{    if (_view = = nil)        {//  load View        [self Loadview];         // called when the view load of the controller is complete         [self viewdidload];    }     return _view;}

5. Controller view the default is almost transparent

Vi. Basic use of navigation controllers

1. The navigation controller must have a root controller

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//1. Create a windowSelf.window =[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; //creating a root controller for a navigation controllerUiviewcontroller *VC =[[Oneviewcontroller alloc] init]; //creating a navigation controller//The navigation controller must have a root controllerUinavigationcontroller *nav =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC]; //2. Setting the root controller of the windowSelf.window.rootViewController =nav; //3. display window[Self.window makekeyandvisible]; returnYES;}

2. If the sub-controller of the navigation controller can get the navigation controller directly

// jump to the second interface -(ibaction) Jump2two: (ID) sender {        //  Create a second controller    Twoviewcontroller *two = [[Twoviewcontroller alloc] init];         // Jump     // if the controller's sub-controller can get the navigation controller directly     [Self.navigationcontroller pushviewcontroller:two animated:yes];}

The 3.initWithRootViewController layer is actually called the navigation controller's push method, the VC becomes the controller's sub-controller

Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC];     // The push method    is called // The Initwithrootviewcontroller layer is actually called the navigation controller's push method, the VC becomes the controller's sub-controller //     [nav pushviewcontroller:vc animated:yes];

iOS Development--ui Advanced (eight) Pickerview simple to use, through the storyboard load controller, register the interface, create a controller through XIB, the controller's view creation, the basic use of the navigation controller

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.