I'm in the process of converting my app into Alloy, however am unsure how i would go about requiring a view and passing data into the required view.
Main View - Browse.xml
<Alloy> <Tab title="Browse" icon="/tabs/browse.png"> <Window class="AppWindow"> <!-- iOS Navigation bar styling --> <TitleControl platform="ios"> <Require src="LogoBar" /> </TitleControl> <ScrollView id="ScrollView"> <Require src="el_storybox" id="el_storybox" /> </ScrollView> </Window> </Tab> </Alloy>I want to require 'el_storybox' which contains the below view:
<Alloy> <View id="storybox"> <Label id="title" /> <View id="lines" /> <View id="seperator" /> <ImageView id="authorimg" /> <ImageView id="authorimg2" /> <Label id="updated_date" /> </View> </Alloy>
Browse.js
// // Require Libs // var api = require('api'); api.StoryBrowse(10, function(success, res, code) { if (success == 1) { // Woo we've got some stories, lets show them.... for ( i = 0; i < res.message.length; i++) { var StoryBox = $.el_storybox.getView(res.message[i]); var boxview = Ti.UI.createView({ top : 20, height : Ti.UI.SIZE }); boxview.add(StoryBox); $.ScrollView.add(boxview); } } else { alert("Error: " + res.message); } });
el_storybox.js
function StoryBox(story) { // // Require Libs // Ti.include('timeago.js'); for ( l = 0; l < story.lines.length; l++) { var line = Ti.UI.createLabel({ title: story.lines[l].text, left : 10, color : Alloy.CFG.storifi.DarkGrey }); $.lines.add(line); } $.title.text = story.title; $.authorimg.image = story.users[0].id.avatar; $.authorimg2.image = story.users[1].id.avatar; $.updated_date.text = humaneDate(story.updated_date); } module.exports = StoryBox;However i keep getting the below error:
-[NSNull krollObjectForBridge:]: unrecognized selector sent to instance 0x44d5068;
For reference, the original script/answer can be found at http://developer.appcelerator.com/question/155875/only-one-view-is-returned