Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26772] iOS: ListView with attributed strings shows "Invalid type passed to function" error.

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionNeeds more info
Resolution Date2019-03-19T17:37:38.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
LabelsattributedString, listView
ReporterJebun Naher
AssigneeAlan Hutton
Created2019-01-27T11:46:32.000+0000
Updated2019-03-25T22:57:43.000+0000

Description

*Issue Description:* When I try to build a project using listView attributed string on iOS, it shows the following error on latest ti SDK 7.5.0.GA *Error Log:*
error log:
[ERROR] Script Error {
[ERROR]     column = 24;
[ERROR]     line = 89;
[ERROR]     message = "Invalid type passed to function";
[ERROR]     nativeLocation = "-[TiUILabel setAttributedString_:] (TiUILabel.m:485)";
[ERROR]     nativeReason = "expected: TiUIAttributedStringProxy, was: NSNull";
[ERROR]     nativeStack = "3   listViewIssue   0x00000001094f3bdb -[TiUIView throwException:subreason:location:] + 107\n4   listViewIssue   0x00000
001095619a7 -[TiUILabel setAttributedString_:] + 503\n5   listViewIssue   0x0000000109576cdf __DoProxyDelegateChangedValuesWithProxy_block_invoke.5
4 + 47\n6   listViewIssue   0x00000001095c005e TiThreadPerformOnMainThread + 78\n7   listViewIssue   0x0000000109576bc5 DoProxyDelegateChangedValue
sWithProxy + 853\n8   listViewIssue   0x00000001094f8744 -[TiUIView propertyChanged:oldValue:newValue:proxy:] + 68\n9   listViewIssue   0x000000010
957c8aa -[TiProxy replaceValue:forKey:notification:] + 1114\n10  listViewIssue   0x000000010957cabd -[TiProxy setValue:forUndefinedKey:] + 77\n11  
listViewIssue   0x00000001094c5b96 -[TiViewProxy setValue:forUndefinedKey:] + 278\n12  Foundation 0x000000010b8750b4 -[NSObject(NSKeyValueCoding) s
etValue:forKey:] + 292\n13  Foundation 0x000000010b875909 -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 271\n14  listViewIssue   0x000000010
972ac5e __28-[TiUIListItem setDataItem:]_block_invoke.338 + 206\n15  CoreFoundation  0x0000000110115c2a -[__NSSetM enumerateObjectsWithOptions:usin
gBlock:] + 218\n16  listViewIssue   0x0000000109729eff -[TiUIListItem setDataItem:] + 4399\n17  listViewIssue   0x000000010973e13a -[TiUIListView t
ableView:heightForRowAtIndexPath:] + 666\n18  UIKitCore  0x000000011b177f2b -[UITableView _dataSourceHeightForRowAtIndexPath:] + 108\n19  UIKitCore
  0x000000011b1c78ba __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 350";
[ERROR]     sourceURL = "file:///Users/user/Library/Developer/CoreSimulator/Devices/38370841-28B4-4E7C-8B1E-89D45DC29E2F/data/Containers/Bundle/App
lication/325AB006-5B5A-4BCB-A0CE-95574C8D6B95/listViewIssue.app/alloy/controllers/index.js";
[ERROR]     stack = "    at [native code]\n    at Controller(/alloy/controllers/index.js:89:24)\n    at createController(/alloy.js:339:52)\n    at 
(/app.js:11:23)\n    at global code(/app.js:13:70)\n    at require@[native code]\n    at (/ti.main.js:27:10)\n    at loadAsync(/ti.internal/bootstr
ap.loader.js:106:11)\n    at global code(/ti.main.js:24:52)";
[ERROR]     toJSON = "<KrollCallback: 0x600002968040>";
[ERROR] } 
[ERROR] Script Error Module "app.js" failed to leave a valid exports object
[DEBUG] Application booted in 646.753073 ms
[ERROR] The application has crashed with an uncaught exception 'org.listviewissue.TiUILabel'.
[ERROR] Reason:
[ERROR] Invalid type passed to function
[ERROR] Stack trace:
[ERROR] 0   CoreFoundation                      0x00000001101a729b __exceptionPreprocess + 331
[ERROR] 1   libobjc.A.dylib                     0x000000010efc8735 objc_exception_throw + 48
[ERROR] 2   listViewIssue                       0x00000001095bfdad TiExceptionThrowWithNameAndReason + 141
[ERROR] 3   listViewIssue                       0x00000001094f3bdb -[TiUIView throwException:subreason:location:] + 107
[ERROR] 4   listViewIssue                       0x00000001095619a7 -[TiUILabel setAttributedString_:] + 503
[ERROR] 5   listViewIssue                       0x0000000109576cdf __DoProxyDelegateChangedValuesWithProxy_block_invoke.54 + 47
[ERROR] 6   listViewIssue                       0x00000001095c005e TiThreadPerformOnMainThread + 78
[ERROR] 7   listViewIssue                       0x0000000109576bc5 DoProxyDelegateChangedValuesWithProxy + 853
[ERROR] 8   listViewIssue                       0x00000001094f8744 -[TiUIView propertyChanged:oldValue:newValue:proxy:] + 68
[ERROR] 9   listViewIssue                       0x000000010957c8aa -[TiProxy replaceValue:forKey:notification:] + 1114
[ERROR] 10  listViewIssue                       0x000000010957cabd -[TiProxy setValue:forUndefinedKey:] + 77
[ERROR] 11  listViewIssue                       0x00000001094c5b96 -[TiViewProxy setValue:forUndefinedKey:] + 278
[ERROR] 12  Foundation                          0x000000010b8750b4 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
[ERROR] 13  Foundation                          0x000000010b875909 -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 271
[ERROR] 14  listViewIssue                       0x000000010972ac5e __28-[TiUIListItem setDataItem:]_block_invoke.338 + 206
[ERROR] 15  CoreFoundation                      0x0000000110115c2a -[__NSSetM enumerateObjectsWithOptions:usingBlock:] + 218
[ERROR] 16  listViewIssue                       0x0000000109729eff -[TiUIListItem setDataItem:] + 4399
[ERROR] 17  listViewIssue                       0x000000010973e13a -[TiUIListView tableView:heightForRowAtIndexPath:] + 666
[ERROR] 18  UIKitCore                           0x000000011b177f2b -[UITableView _dataSourceHeightForRowAtIndexPath:] + 108
[ERROR] 19  UIKitCore                           0x000000011b1c78ba __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_inv
oke + 350
[ERROR] 20  UIKitCore                           0x000000011b1c7112 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 3281
[ERROR] 21  UIKitCore                           0x000000011b1cd151 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 487
[ERROR] 22  UIKitCore                           0x000000011b1cd2b7 -[UITableViewRowData heightForTable] + 61
[ERROR] 23  UIKitCore                           0x000000011b12698f -[UITableView _updateContentSize] + 354
[ERROR] 24  UIKitCore                           0x000000011b14d587 -[UITableView setTableHeaderView:] + 466
[ERROR] 25  listViewIssue                       0x0000000109732413 __33-[TiUIListView proxyDidRelayout:]_block_invoke + 307
[ERROR] 26  libdispatch.dylib                   0x00000001116b951d _dispatch_call_block_and_release + 12
[ERROR] 27  libdispatch.dylib                   0x00000001116ba587 _dispatch_client_callout + 8
[ERROR] 28  libdispatch.dylib                   0x00000001116c63bc _dispatch_main_queue_callback_4CF + 1290
[ERROR] 29  CoreFoundation                      0x000000011010a7f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
[ERROR] 30  CoreFoundation                      0x0000000110104e86 __CFRunLoopRun + 2342
[ERROR] 31  CoreFoundation                      0x0000000110104221 CFRunLoopRunSpecific + 625
[ERROR] 32  GraphicsServices                    0x00000001133531dd GSEventRunModal + 62
[ERROR] 33  UIKitCore                           0x000000011abf6115 UIApplicationMain + 140
[ERROR] 34  listViewIssue                       0x000000010948c263 main + 115
[ERROR] 35  libdyld.dylib                       0x000000011172a551 start + 1
-- End simulator log ---------------------------------------------------------
users-MacBook-Pro-2:listViewIssue user$ 
*Steps to Reproduce:* 1. Replace index.xml, index.js, index.tss with the following test code. *index.xml*
<Alloy>
	<Window class="container">
		<ListView id="listView">
			<Templates>
				<ItemTemplate name="simpleLabel">
					<Label bindId="label1" id="label1"/>
				</ItemTemplate>
			</Templates>
		</ListView>
	</Window>
</Alloy>
*index.js*
var listSection = Ti.UI.createListSection();
var dataItems = [];

for (var i = 0; i < 100; i++) {

	var data = {
		template : "simpleLabel",
		label1 : {},
	};

	if (i % 2 === 1) {

		data.label1.attributedString = Ti.UI.createAttributedString({
			text : "Italic row row row" + i,
			attributes : [{
				type : Ti.UI.ATTRIBUTE_FONT,
				value : {
					fontWeight : "normal",
					fontStyle : "italic",
				},
				range : [0, 6],
			}]
		});

	} else {
		//data.label1.text = "Normal";
		data.label1.text = "Normal" + i;
	}

	dataItems.push(data);
};
listSection.setItems(dataItems);
$.listView.setSections([listSection]);
$.index.open(); 
*index.tss*
".container": {
	backgroundColor: "#fff",
	layout: "vertical",
}
 
"#listView": {
	height: Ti.UI.FILL,
	width: Ti.UI.FILL,
}
"#label1": {
	font: {
		fontSize: 26,
	},
	color: "#000",
}
 
"Label": {
	color: "#000",
	font: {
		fontSize: 30,
	},
}
2. Build the project on iOS simulator and observe the error. *Expected:* ListView attributed string should work *Actual:* It doesn't work, generates the said error.

Comments

  1. Hans Knöchel 2019-01-27

    If one label uses a text and one uses attributed strings, you should consider using two templates instead. That's what we use and it works good.
  2. Alan Hutton 2019-03-19

    As this issue has been closed in intercom for not getting customer reply, we can close this issue for now.

JSON Source