Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

iPhone Multiple Picker in One View Issue

$
0
0

Just updated Titanium to 3.4.1 and the XCODE to 6.1 on the Mac. Prior to the update the app has been working flawlessly. The issue I have now is on the first view of a form on my app that has 3 picker views. The first one is ok but the second and third one are automatically open. I tried to change some settings but haven't been able to figure it out. I don't want to have the picker open in a separate window if I don't have to. I was wondering if someone can see the code and point me in the right direction. Thanks for your help by the way. Here is the code.

Picker 1

var tr = Titanium.UI.create2DMatrix();
    tr = tr.rotate(90);
 
    var drop_button = Titanium.UI.createButton({
        style : Titanium.UI.iPhone.SystemButton.DISCLOSURE,
        transform : tr
    });
 
    var aTextField_TypeOne = Titanium.UI.createTextField({
        top : '36%',
        width : '80%',
        height : '8%',
        value : 'Type One (Click Circle)',
        color : styles.textfield.color,
        font : styles.textfield.font,
        paddingLeft : styles.textfield.paddingLeft,
        backgroundImage : styles.textfield.backgroundImage,
        borderStyle : Titanium.UI.INPUT_BORDERSTYLE_NONE,
        rightButton : drop_button,
        rightButtonMode : Titanium.UI.INPUT_BUTTONMODE_ALWAYS
    });
 
    // On focus hide the Picker and emulate the "hintText" behavior
    aTextField_TypeOne.addEventListener('focus', function(e) {
 
        if (aTextField_TypeOne.value == 'Type One (Click Circle)') {
            aTextField_TypeOne.value = '';
        }
    });
    // On blur emulate the "hintText" behavior
    aTextField_TypeOne.addEventListener('blur', function(e) {
        if (aTextField_TypeOne.value == '') {
            aTextField_TypeOne.value = 'Type One (Click Circle)';
        }
    });
 
    //picker 1
 
    var picker_view = Titanium.UI.createView({
        height : 251,
        visible : false,
        bottom : 0
 
    });
    var cancel = Titanium.UI.createButton({
        title : 'Cancel',
        style : Titanium.UI.iPhone.SystemButtonStyle.BORDERED
    });
    var done = Titanium.UI.createButton({
        title : 'Done',
        style : Titanium.UI.iPhone.SystemButtonStyle.DONE
    });
    var spacer = Titanium.UI.createButton({
        systemButton : Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
    });
    var toolbar = Titanium.UI.createToolbar({
        top : 0,
        width : 320,
        items : [cancel, spacer, done]
    });
    var picker = Titanium.UI.createPicker({
        top : 43
    });
    picker.selectionIndicator = true;
 
    var picker_data = [Titanium.UI.createPickerRow({
        title : '1'
    }), Titanium.UI.createPickerRow({
        title : '2'
    }), Titanium.UI.createPickerRow({
        title : '3'
    })];
    picker.add(picker_data);
    picker_view.add(toolbar);
    picker_view.add(picker);
    var slide_in = Titanium.UI.createAnimation({
        bottom : 0
    });
    var slide_out = Titanium.UI.createAnimation({
        bottom : -251
    });
    aTextField_TypeOne.addEventListener('focus', function() {
        picker_view.animate(slide_out);
    });
 
    drop_button.addEventListener('click', function() {
        picker_view.visible = true;
        picker_view.animate(slide_in);
        aTextField_TypeOne.blur();
    });
 
    cancel.addEventListener('click', function() {
        picker_view.animate(slide_out);
    });
 
    done.addEventListener('click', function() {
        aTextField_TypeOne.value = picker.getSelectedRow(0).title;
        picker_view.animate(slide_out);
        aTextField_TypeOne.text = picker.getSelectedRow(0).title;
    });
Picker 2
var tr = Titanium.UI.create2DMatrix();
    tr = tr.rotate(90);
    var drop_button1 = Titanium.UI.createButton({
        style : Titanium.UI.iPhone.SystemButton.DISCLOSURE,
        transform : tr
    });
 
    var aTextField_other = Titanium.UI.createTextField({
        top : '45%',
        width : '80%',
        height : '8%',
        value : 'Other (Click Circle)',
        color : styles.textfield.color,
        font : styles.textfield.font,
        paddingLeft : styles.textfield.paddingLeft,
        backgroundImage : styles.textfield.backgroundImage,
        borderStyle : Titanium.UI.INPUT_BORDERSTYLE_NONE,
        rightButton : drop_button1,
        rightButtonMode : Titanium.UI.INPUT_BUTTONMODE_ALWAYS
 
    });
 
    // On focus hide the Picker and emulate the "hintText" behavior
    aTextField_other.addEventListener('focus', function(e) {
 
        if (aTextField_other.value == 'Other (Click Circle)') {
            aTextField_other.value = '';
        }
    });
    // On blur emulate the "hintText" behavior
    aTextField_other.addEventListener('blur', function(e) {
        if (aTextField_other.value == '') {
            aTextField_other.value = 'Other (Click Circle)';
        }
    });
 
    var picker_view1 = Titanium.UI.createView({
        height : 251,
        visible : false,
        bottom : 0
    });
 
    var cancel1 = Titanium.UI.createButton({
        title : 'Cancel',
        style : Titanium.UI.iPhone.SystemButtonStyle.BORDERED
    });
 
    var done1 = Titanium.UI.createButton({
        title : 'Done',
        style : Titanium.UI.iPhone.SystemButtonStyle.DONE
    });
 
    var spacer1 = Titanium.UI.createButton({
        systemButton : Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
    });
 
    var toolbar1 = Titanium.UI.createToolbar({
        top : 0,
        width : 320,
        items : [cancel1, spacer1, done1]
    });
 
    var picker1 = Titanium.UI.createPicker({
        top : 43
    });
    picker1.selectionIndicator = true;
 
    var picker_data1 = [Titanium.UI.createPickerRow({
        title : '0'
    }), Titanium.UI.createPickerRow({
        title : '1'
    }), Titanium.UI.createPickerRow({
        title : '2'
    }), Titanium.UI.createPickerRow({
        title : '3'
    }), Titanium.UI.createPickerRow({
        title : '4'
    }), Titanium.UI.createPickerRow({
        title : '5'
    })];
 
    picker1.add(picker_data1);
    picker_view1.add(toolbar1);
    picker_view1.add(picker1);
 
    var slide_in1 = Titanium.UI.createAnimation({
        bottom : 0
    });
 
    var slide_out1 = Titanium.UI.createAnimation({
        bottom : -251
    });
 
    aTextField_other.addEventListener('focus', function() {
        picker_view1.animate(slide_out1);
    });
 
    drop_button1.addEventListener('click', function() {
        picker_view1.visible = true;
        picker_view1.animate(slide_in1);
        aTextField_other.blur();
 
    });
 
    cancel1.addEventListener('click', function() {
        picker_view1.animate(slide_out1);
    });
 
    done1.addEventListener('click', function() {
        var dependants = picker1.getSelectedRow(0).title;
        var dependantquantity = dependants.split(" ");
        Ti.App.Properties.setInt('dependanttnum', dependantquantity[0]);
        aTextField_other.value = picker1.getSelectedRow(0).title;
        picker_view1.animate(slide_out1);
        aTextField_other.text = picker1.getSelectedRow(0).title;
    });
Picker 3
var tr = Titanium.UI.create2DMatrix();
    tr = tr.rotate(90);
 
    var drop_button2 = Titanium.UI.createButton({
        style : Titanium.UI.iPhone.SystemButton.DISCLOSURE,
        transform : tr
    });
 
    var aTextField_status = Titanium.UI.createTextField({
        top : '54%',
        width : '80%',
        height : '8%',
        value : 'Status (Click Circle)',
        color : styles.textfield.color,
        font : styles.textfield.font,
        paddingLeft : styles.textfield.paddingLeft,
        backgroundImage : styles.textfield.backgroundImage,
        borderStyle : Titanium.UI.INPUT_BORDERSTYLE_NONE,
        rightButton : drop_button2,
        rightButtonMode : Titanium.UI.INPUT_BUTTONMODE_ALWAYS
    });
 
    // On focus hide the Picker and emulate the "hintText" behavior
    aTextField_status.addEventListener('focus', function(e) {
 
        if (aTextField_status.value == 'Status (Click Circle)') {
            aTextField_status.value = '';
        }
    });
    // On blur emulate the "hintText" behavior
    aTextField_status.addEventListener('blur', function(e) {
        if (aTextField_status.value == '') {
            aTextField_status.value = 'Status (Click Circle)';
        }
    });
 
    var picker_view2 = Titanium.UI.createView({
        height : 251,
        visible : false,
        bottom : 0
 
    });
 
    var cancel2 = Titanium.UI.createButton({
        title : 'Cancel',
        style : Titanium.UI.iPhone.SystemButtonStyle.BORDERED
    });
 
    var done2 = Titanium.UI.createButton({
        title : 'Done',
        style : Titanium.UI.iPhone.SystemButtonStyle.DONE
    });
 
    var spacer2 = Titanium.UI.createButton({
        systemButton : Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
    });
 
    var toolbar2 = Titanium.UI.createToolbar({
        top : 0,
        width : 320,
        items : [cancel2, spacer2, done2]
    });
 
    var picker2 = Titanium.UI.createPicker({
        top : 43
    });
    picker2.selectionIndicator = true;
 
    var picker_data2 = [Titanium.UI.createPickerRow({
        title : 'See Options'
    }), Titanium.UI.createPickerRow({
        title : 'Red'
    }), Titanium.UI.createPickerRow({
        title : 'Blue'
    }), Titanium.UI.createPickerRow({
        title : 'Green'
    })];
    picker2.add(picker_data2);
    picker_view2.add(toolbar2);
    picker_view2.add(picker2);
 
    var slide_in2 = Titanium.UI.createAnimation({
        bottom : 0
    });
 
    var slide_out2 = Titanium.UI.createAnimation({
        bottom : -251
    });
 
    aTextField_status.addEventListener('focus', function() {
        picker_view2.animate(slide_out2);
    });
 
    drop_button2.addEventListener('click', function() {
        picker_view2.visible = true;
        picker_view2.animate(slide_in2);
        aTextField_status.blur();
    });
 
    cancel2.addEventListener('click', function() {
        picker_view2.animate(slide_out2);
    });
 
    done2.addEventListener('click', function() {
        aTextField_status.value = picker2.getSelectedRow(0).title;
        picker_view2.animate(slide_out2);
        aTextField_status.text = picker2.getSelectedRow(0).title;
    });

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>