ios使用jspatch中需要注意的事項


第一份代碼,為了糾正原代碼不顯示29號的bug,先上代碼

 1 require('NSString','MCDatePickType','NSMutableArray','UIButton');
 2 
 3 defineClass('MMCDatePickView',{
 4 
 5     setDatePickViewSelected: 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()));
10     self.setSelectedMinuteRow(self.minutesArray().indexOfObject(NSString.stringWithFormat("%@分", self.currentMinuteString())));
11 
12 
13     // 設置年和月
14      var MonthAndYear = self.currentYearString().toJS() + '年' + self.currentMonthString().toJS() + '月';
15 
16     if (self.type() === 0) {
17 
18 
19         for (var i = 0; i < self.yearArray().count(); i++) {
20             
21             var jsArray = self.yearArray().toJS();
22             var year = jsArray[i];
23             if (year == self.currentYearString().toJS()) {
24                 
25                 self.datePickView().selectRow_inComponent_animated(i, 0, YES);
26 
27                 break;
28             }
29         }
30 
31         
32     } 
33     else {
34 
35 
36       self.setSelectedMonthRow(self.yearAndMonthArray().indexOfObject(MonthAndYear));
37       self.datePickView().selectRow_inComponent_animated(self.selectedMonthRow(), 0, YES);
38        
39 
40     if (self.type() !== 0 && self.type() !== 1 && self.type() !== 5) {
41         self.datePickView().selectRow_inComponent_animated(self.selectedDayRow(), 1, YES);
42     }
43 
44 
45     //選中小時
46     if (self.type() === 3 || self.type() === 4) {
47         self.datePickView().selectRow_inComponent_animated(self.selectedHourRow(), 2, YES);
48     }
49 
50     //選中分
51     if (self.type() === 4) {
52         self.datePickView().selectRow_inComponent_animated(self.selectedMinuteRow(), 3, YES);
53     }
54 
55 
56     // 選中自定義的
57     if (self.type() === 5) {
58         self.datePickView().selectRow_inComponent_animated(self.customerIndex(), 0, YES);
59     }
60 }
61 }
62 });

 

注意事項:

1.在對字符或者數組,字典操作的時候應該轉成js的字符串或者字典,等等

 1 var MonthAndYear = self.currentYearString().toJS() + '年' + self.currentMonthString().toJS() + '月'; 

上邊的代碼是正確的,MonthAndYear 就是js格式的字符串,下邊的是不對的:

var MonthAndYear = self.currentYearString() + '年' + self.currentMonthString() + '月';

2.在進行比較的時候,使用相同類型,js的數據類型和oc的不一樣

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 是弱類型語言,不強調類型,oc的枚舉在js中不好使,

 1 self.type() === 0 

最終還是把枚舉轉成了基本數據類型

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM