The use of Ios:uipickerview selectors

Source: Internet
Author: User

A date schedule that is similar to a password lock through the Uipickerview selector

The source code is as follows:

1 #import <UIKit/UIKit.h> 2  3 @interface Viewcontroller:uiviewcontroller<uipickerviewdatasource, Uipickerviewdelegate> 4 @property (strong,nonatomic) Nsarray *weeks;//Show data for first column 5 @property (strong,nonatomic) Nsarray *time; Show data for the second column 6  7 @property (strong,nonatomic) Nsarray *years;   Display the third column shows the Year 8 @property (strong,nonatomic) Nsarray *months;  Shows the fourth column showing the month 9 @property (strong,nonatomic) Nsarray *days;    Displays the fifth column showing Day @property (assign,nonatomic) Nsinteger number;12 @property (strong,nonatomic) nsstring *str;13 @end

  1 #import "ViewController.h" 2 3 @interface Viewcontroller () 4 @property (weak, nonatomic) Iboutlet Uipickerview *p  Ickerview;  5 6 @end 7 8 @implementation Viewcontroller 9-(void) Viewdidload {Ten [Super Viewdidload]; 11 12//Initialization Self.weeks = [Nsarray arraywithobjects:@ "Mon", @ "Tus", @ "Thi", @ "Wen", @ "Fir", @ "Sat", @ "Sun", nil]; Self.time = [Nsarray arraywithobjects:@ "Morning", @ "noon", @ "Afternoon", nil]; Self.years = [Nsarray arraywithobjects:@ "2000", @ "2001", @ "2002", @ "2003", @ "2004", @ "2005", @ "2006", @ "2007", @ "20 ", @", "@", @ "," @ ", @", @ "," @ ", nil]; Self.months = [Nsarray arraywithobjects:@ "1", @ "2", @ "3", @ "4", @ "5", @ "6", @ "7", @ "8", @ "9", @ "10", @ "11", @ "n", Nil]; Self.days = [Nsarray arraywithobjects:@ "01", @ "02", @ "03", @ "04", @ "05", @ "06", @ "07", @ "08", @ "09", @ "10", @ "11", @ "1 2 ", @" 13 ", @" 14 ", @" 15 ", @" 16 ", @" 17 ", @" 18 ", @" 19 ", @" 20 ", @" 21 ", @" 22 ", @" 23 ", @" 24 ", @" 25 ", @" 26 ", @" 27 ", @" 28 ", @" 29 ", @" 30 " , @ "+", nIL]; 23 24 25//Set Pickerview DataSource and delegate to Self.pickerView.dataSource = self; Self.pickerView.delegate = self; (void) didreceivememorywarning {[Super didreceivememorywarning];/Dispose of any of the resources that can be recreated. The proxy method for the #pragma mark-pickerview 35 36//Set how many columns of PNS-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) pic Kerview 5 (40} 41 42//Set number of rows per column-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincom Ponent: (Nsinteger) component (component), 0:48 Self.number = SELF.W Eeks.count; ; Case 1:51 self.number = Self.time.count; a break; 2:54 self.number = Self.years.count; ; 3:57 self.number = Self.months.count; break; 4:60 Self.number = selF.days.count; a break; The Self.number return; 65 66} 67 68//Set the content displayed per column per row-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row Forcomp Onent: (Nsinteger) component {0:75 switch (component), and the "Self.str" (the "case") = SE Lf.weeks[row]; break; 1:78 self.str = Self.time[row]; ; 2:81 self.str = Self.years[row]; A. 3:84 self.str = Self.months[row]; ; 4:87 self.str = Self.days[row]; a break; SELF.STR;  92 93} 94 95//obtain data via proxy method Didselectrows-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) row    Incomponent: (Nsinteger) component/98//nslog (@ "column:%ld, line:%ld", Component,row); Component Switch (101 case 0:102)            NSLog (@ "%@", [NSString stringwithformat:@ "%@,%@,%@,%@,%@", Self.weeks[row],self.time[[pickerview selectedRowInCo Mponent:1]],self.years[[pickerview Selectedrowincomponent:2]],self.months[[pickerview SelectedRowInComponent:3]] , Self.days[[pickerview Selectedrowincomponent:4]]), 103 break;104 case 1:105 NSLog (@ "%@", [ NSString stringwithformat:@ "%@,%@,%@,%@,%@", Self.weeks[[pickerview Selectedrowincomponent:0]],self.time[row], Self.years[[pickerview Selectedrowincomponent:2]],self.months[[pickerview selectedrowincomponent:3]],self.days[[ Pickerview Selectedrowincomponent:4]] 106 break;107 case 2:108 NSLog (@ "%@", [NSString str ingwithformat:@ "%@,%@,%@,%@,%@", Self.weeks[[pickerview Selectedrowincomponent:0]],self.time[[pickerview Selectedrowincomponent:1]],self.years[row],self.months[[pickerview selectedrowincomponent:3]],self.days[[        Pickerview Selectedrowincomponent:4]] 109 break;110 case 3:111     NSLog (@ "%@", [NSString stringwithformat:@ "%@,%@,%@,%@,%@", Self.weeks[[pickerview selectedrowincomponent:0]], Self.time[[pickerview Selectedrowincomponent:1]],self.years[[pickerview selectedrowincomponent:2]],self.months[ Row],self.days[[pickerview Selectedrowincomponent:4]]); break;113 case 4:114 NSLog (@ "% @ ", [nsstring stringwithformat:@"%@,%@,%@,%@,%@ ", Self.weeks[[pickerview selectedrowincomponent:0]],self.time[[ Pickerview Selectedrowincomponent:1]],self.years[[pickerview Selectedrowincomponent:2]],self.months[[pickerview Selectedrowincomponent:3]],self.days[row]); break;116}117}118 @end

Use of the Ios:uipickerview selector

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.