The first code, in order to correct the original code does not display 29th number of bugs, first on the code
1Require (' nsstring ', ' mcdatepicktype ', ' nsmutablearray ', ' UIButton ');2 3DefineClass (' Mmcdatepickview ',{4 5Setdatepickviewselected:function() {6 7 Self.setselectedyearrow (Self.yeararray (). Indexofobject (Self.currentyearstring ()));8 Self.setselecteddayrow (self. Daysarray (). Indexofobject (Self.currentdaystring ()));9 Self.setselectedhourrow (Self.hoursarray (). Indexofobject (Self.currenthourstring ()));TenSelf.setselectedminuterow (Self.minutesarray (). Indexofobject (Nsstring.stringwithformat ("%@ min"), self.currentminutestring () ))); One A - //set year and month - varMonthandyear = Self.currentyearstring (). Tojs () + ' year ' + self.currentmonthstring (). Tojs () + ' month '; the - if(Self.type () = = = 0) { - - + for(vari = 0; I < Self.yeararray (). Count (); i++) { - + varJsarray =Self.yeararray (). Tojs (); A varYear =Jsarray[i]; at if(Year = =self.currentyearstring (). TOJS ()) { - -Self.datepickview (). selectrow_incomponent_animated (i, 0, YES); - - Break; - } in } - to + } - Else { the * $ Self.setselectedmonthrow (Self.yearandmontharray (). Indexofobject (Monthandyear));Panax NotoginsengSelf.datepickview (). selectrow_incomponent_animated (Self.selectedmonthrow (), 0, YES); - the + if(Self.type ()!== 0 && self.type ()!== 1 && self.type ()!== 5) { ASelf.datepickview (). selectrow_incomponent_animated (Self.selecteddayrow (), 1, YES); the } + - $ //Selected Hours $ if(Self.type () = = = 3 | | self.type () = = = 4) { -Self.datepickview (). selectrow_incomponent_animated (Self.selectedhourrow (), 2, YES); - } the - //Selected pointsWuyi if(Self.type () = = = 4) { theSelf.datepickview (). selectrow_incomponent_animated (Self.selectedminuterow (), 3, YES); - } Wu - About //Select the custom $ if(Self.type () = = = 5) { -Self.datepickview (). selectrow_incomponent_animated (Self.customerindex (), 0, YES); - } - } A } +});
Precautions:
1. In the character or array, dictionary operation should be converted to JS string or dictionary, etc.
1 var monthandyear = self.currentyearstring (). Tojs () + ' year ' + self.currentmonthstring (). Tojs () + ' month ';
The above code is correct, Monthandyear is the JS format of the string, the bottom is not right:
var Monthandyear = self.currentyearstring () + ' year ' + self.currentmonthstring () + ' month ';
2. When comparing, using the same type, JS data type and OC is not the same
1 var jsarray = self.yeararray (). Tojs (); 2 var year = jsarray[i]; 3 if (Year = = self.currentyearstring (). Tojs ()) {4 5 Self.datepickview (). selectrow_incomponent_animated (i, 0, YES); 6 7 Break ; 8 }
3.js is a weak type language, does not emphasize the type, OC enumeration in JS does not do,
1 self.type () = = = 0
Finally, it turns the enumeration into a basic data type.
Things to remember about iOS using Jspatch