ToolbarPressed

If I add 2 toolbar buttons in the open event how do I address them in the Toolbarpressed event? I don’t have a problem if I add them from the library as I just put the name in the case structure but that doesn’t seem to work if I add them by code

Toolbar.Add(iOSToolButton.NewSystemItem(iOSToolButton.Types.SystemAdd)) Toolbar.Add(iOSToolButton.NewSystemItem(iOSToolButton.Types.SystemTrash))

select case button
case SystemTrash
MessageBox1.Show
case SystemAdd
MessageBox2.Show
end select

Did you try using a tag to identify? https://documentation.xojo.com/api/deprecated/iostoolbutton.html#iostoolbutton-tag

Try something like this:

Select Case button.Type Case iOSToolButton.Types.SystemTrash Label1.Text = "Trash" Case iOSToolButton.Types.SystemAdd Label1.Text = "Add" End Select

You can also use non-standard buttons. So in the Open event handler of a View:

[code]Dim button As iOSToolButton

// Add New Ship Button
button = iOSToolButton.NewSystemItem(iOSToolButton.Types.SystemAdd)
RightNavigationToolbar.Add(button)

// Add Delete Ship Button
button = iOSToolButton.NewSystemItem(iOSToolButton.Types.SystemTrash)
button.Enabled = False 'Initially disabled
RightNavigationToolbar.Add(button)

// Add Duplicate Ship Button
button = iOSToolButton.NewPlain(iOSImage.SystemImage(“plus.square.on.square”,0,iosimage.SystemImageWeights.Unspecified,Nil,Nil))
RightNavigationToolbar.Add(button)
[/code]

And then in the ToolbarPressed handler:

[code]Select Case button.Type
Case iOSToolButton.Types.SystemAdd
// Create new ship

Case iOSToolButton.Types.SystemTrash
// Delete an existing ship

Else 'Duplicate

End Select
[/code]

You can also reference buttons by number, but I find this confusing.

Art, For your additional Duplicate Ship button, if it wasn’t the ELSE option in the Case what would it’s specific case button.type be or how would you tag it?

If there were two additional toolbuttons you would need to define a tag upon creation, and check the tag in the ToolbarPressed event.

When I add toolbuttons to an iOS view I never use the layout editor, always add them by code. And I always define a tag for each button.
This is of course a personal choice, but after making many iOS apps I realized that adding the toolbuttons by code gives me more flexibility.

Something like:

deletebutton = RightNavigationToolbar.Value(1) 'System Trash Button