加载 window 后更改选择器行
Change Picker Rows after window is loaded
我正在尝试在 window 加载后更改选择器行。选择器是在 xml file
中创建的,但是当试图向其中添加一行时会抛出错误(见下文)。
选择器添加后如何添加选择器行?
view.xml
<!-- other parent views above -->
<Picker id="languagePicker" selectionIndicator="true" useSpinner="true"
width="Ti.Platform.displayCaps.platformWidth" right="0">
</Picker>
view.js
var languages = db.execute("SELECT * FROM language");
while(languages.isValidRow()){
$.languagePicker.add(Ti.UI.createPickerRow({title:languages.fieldByName('language')}));
languages.next();
}
错误日志:
[ERROR] The application has crashed with an uncaught exception 'NSInvalidArgumentException'.
Reason:
-[NSNull rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x109f28af0
Stack trace:
0 CoreFoundation 0x0000000109d03e4d exceptionPreprocess + 141
1 libobjc.A.dylib 0x00000001096d5deb objc_exception_throw + 48
2 CoreFoundation 0x0000000109d0c48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000109c5990a ___forwarding_ + 970
4 CoreFoundation 0x0000000109c594b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000106466d9c -[UILabel _contentInsetsFromFonts] + 137
6 UIKit 0x0000000106782a84 -[_UILabelLayer updateContentInsets] + 127
7 UIKit 0x0000000106782b73 -[_UILabelLayer updateContentLayerSize] + 50
8 UIKit 0x0000000106782ce1 -[_UILabelLayer layoutSublayers] + 25
9 QuartzCore 0x000000010875fe70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
10 QuartzCore 0x000000010875fcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
11 QuartzCore 0x0000000108754475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
12 QuartzCore 0x0000000108781c0a _ZN2CA11Transaction6commitEv + 486
13 QuartzCore 0x000000010878237c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
14 CoreFoundation 0x0000000109c2f367 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
15 CoreFoundation 0x0000000109c2f2d7 __CFRunLoopDoObservers + 391
16 CoreFoundation 0x0000000109c24f2b __CFRunLoopRun + 1147
17 CoreFoundation 0x0000000109c24828 CFRunLoopRunSpecific + 488
18 GraphicsServices 0x000000010b04bad2 GSEventRunModal + 161
19 UIKit 0x00000001061f9610 UIApplicationMain + 171
20 ISTQB 0x0000000104320de6 main + 310
21 libdyld.dylib 0x000000010a95192d start + 1
picker.add()
方法需要一个 PickerRow
对象数组。这适用于我的应用程序:
var data = [],
picker = Ti.UI.createPicker();
data.push(
Ti.UI.createPickerRow({
title: 'Row 1'
}));
data.push(
Ti.UI.createPickerRow({
title: 'Row2'
}));
picker.add(data);
见http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Picker-method-add
我正在尝试在 window 加载后更改选择器行。选择器是在 xml file
中创建的,但是当试图向其中添加一行时会抛出错误(见下文)。
选择器添加后如何添加选择器行?
view.xml
<!-- other parent views above -->
<Picker id="languagePicker" selectionIndicator="true" useSpinner="true"
width="Ti.Platform.displayCaps.platformWidth" right="0">
</Picker>
view.js
var languages = db.execute("SELECT * FROM language");
while(languages.isValidRow()){
$.languagePicker.add(Ti.UI.createPickerRow({title:languages.fieldByName('language')}));
languages.next();
}
错误日志:
[ERROR] The application has crashed with an uncaught exception 'NSInvalidArgumentException'. Reason: -[NSNull rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x109f28af0 Stack trace: 0 CoreFoundation 0x0000000109d03e4d exceptionPreprocess + 141 1 libobjc.A.dylib 0x00000001096d5deb objc_exception_throw + 48 2 CoreFoundation 0x0000000109d0c48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x0000000109c5990a ___forwarding_ + 970 4 CoreFoundation 0x0000000109c594b8 _CF_forwarding_prep_0 + 120 5 UIKit 0x0000000106466d9c -[UILabel _contentInsetsFromFonts] + 137 6 UIKit 0x0000000106782a84 -[_UILabelLayer updateContentInsets] + 127 7 UIKit 0x0000000106782b73 -[_UILabelLayer updateContentLayerSize] + 50 8 UIKit 0x0000000106782ce1 -[_UILabelLayer layoutSublayers] + 25 9 QuartzCore 0x000000010875fe70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 10 QuartzCore 0x000000010875fcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 11 QuartzCore 0x0000000108754475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 12 QuartzCore 0x0000000108781c0a _ZN2CA11Transaction6commitEv + 486 13 QuartzCore 0x000000010878237c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 14 CoreFoundation 0x0000000109c2f367 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 15 CoreFoundation 0x0000000109c2f2d7 __CFRunLoopDoObservers + 391 16 CoreFoundation 0x0000000109c24f2b __CFRunLoopRun + 1147 17 CoreFoundation 0x0000000109c24828 CFRunLoopRunSpecific + 488 18 GraphicsServices 0x000000010b04bad2 GSEventRunModal + 161 19 UIKit 0x00000001061f9610 UIApplicationMain + 171 20 ISTQB 0x0000000104320de6 main + 310 21 libdyld.dylib 0x000000010a95192d start + 1
picker.add()
方法需要一个 PickerRow
对象数组。这适用于我的应用程序:
var data = [],
picker = Ti.UI.createPicker();
data.push(
Ti.UI.createPickerRow({
title: 'Row 1'
}));
data.push(
Ti.UI.createPickerRow({
title: 'Row2'
}));
picker.add(data);
见http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Picker-method-add