bilalq
bilalq

Reputation: 7679

How do you add a rightNavButton to an iOS app when using Titanium Alloy?

I'm trying to create a rightNavButton for a window.

The code in my view looks something like this:

<Alloy>
  <Window title="TabName" id="myWindow">
    <Label>Text</Label>
    <Button id="topRight">Foo</Button>
  </Window>
</Alloy>

I was trying to come up with a way to set the rightNavButton of the window to something, and thought setting the property in the controller would be the way to go. I can get a button to be in the top right, but it will always exist in the window as well.

$.myWindow.rightNavButton = $.topRight;

I've thought about creating a separate view for the button and requiring it somehow, but I'm not sure how to do that. I'm not even sure if that's the proper thing to do.

Any help would be appreciated!


Edit:

I sort of have a workaround now.

$.myWindow.rightNavButton = Ti.UI.createButton({title: 'topRight'});

That code in the controller works, but it seems to defeat the whole point of using alloy. Now that button will no longer exist in the XML file.

Upvotes: 2

Views: 2069

Answers (1)

Aaron Saunders
Aaron Saunders

Reputation: 33345

take a look at my project here https://github.com/aaronksaunders/alloy_fugitive

I add the button to the view.xml and then just set it in the controller

$.fugitiveWindow.setRightNavButton($.add);

in the view.xml

<Alloy>
    <Tab id="fugitiveTab" title="Fugitives">
        <Window id="fugitiveWindow"  title="Fugitives" class='container'>
            <TableView id="table"/>
            <!-- hidden and used later -->
            <Button id="add" title="Add" top="-50dp"></Button>
        </Window>
    </Tab>
</Alloy>

Upvotes: 5

Related Questions