Question

I want to show a view with some data about current day, and I want to allow user to swipe back to previous days.

I mean, I want to show some info and if the user swipe to another day, it will be the same design with different data.

What is the easiest way to do this?

I'm thinking in using scrollableview with the same view in views params and change their data when user change the view.

I use this:

var scrollableView = Ti.UI.createScrollableView({
    views : [view1, view1, view1],
    showPagingControl : true
});

But this doesn't work, it only show the first view1.

The other way I've found is creating different views and load the correct view. It works, but I have to duplicate a lot of code (interface will be the same in the different views, it only changes the data) and of course, it isn't the best way.

Do you know how I can do this?

Thanks in advance

Was it helpful?

Solution

Use a commonJS module that wraps a view, then change the view parameters, heres a quick example:

// myView.js
function MyView(title, color) {
    var self = Ti.UI.createView({backgroundColor : color});
    var label = Ti.UI.createLabel({text: 'A simple label'});
    // Add other components to your custom view
    self.add(label);
    return self;
}

// Dont forget this!
module.exports = MyView;

Now require you're custom module and use it in your scrollable view:

var MyView = require('MyView');
var scrollableView = Ti.UI.createScrollableView({
    views : [new MyView("View 1", "red"), new MyView("View 2", "green"), new MyView("View 3", "blue")],
    showPagingControl : true
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top