iOS Question How do I create an action sheet?

davepamn

Active Member
Licensed User
Longtime User
I need to create an action sheet where the user select one of many items. Do I use activity form to do this or a custom dialog box? If a dialog box is there a custom library like those in b4a?
 

klaus

Expert
Licensed User
Longtime User
You need to:
1) Dim the ActionSheet in Process_Globals
Private ashPages As ActionSheet

2) Initialize it in Application_Start.
ashEdit.Initialize("ashEdit", "", "Cancel", "Delete", Array As String("Add", "Edit", "Insert"))
Initialize parameters:
Initialize(EventName As String, Title As String, CancelItem As String, DestructiveItem As String, OtherItems As List)
Apple recommends to not use the Title.
Apple documentation.

3) Add an event routine.
B4X:
' ActionSheet Edit event routine
Private Sub ashEdit_Click(Item As String)
    Select Item
    Case "Cancel"
        Msgbox("'Cancel' clicked", "Editing")
    Case "Add"
        Msgbox("'Add' clicked", "Editing")
    Case "Edit"
        Msgbox("'Edit' clicked", "Editing")
    Case "Insert"
        Msgbox("'Insert' clicked", "Editing")
    Case "Delete"
        Msgbox2("msgDelete", "Dou you really want to delete the entry ?", "Editing", Array ("Yes", "No"))
    End Select
End Sub

4) Show the ActionSheet somewhere in the code.
Can be any Page.RootPanel.
ashEdit.Show(Page1.RootPanel)

The ActionSheet will look like this:

 
Last edited:
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
B4X:
Private Sub Application_Start (Nav As NavigationController)
    ashColor.Initialize("AshColor","Pick a Color","Cancel","Delete",ArrayAsString("Red","Green","Blue"))
End Sub
Sub cmdSelectAColor_Click

    ashColor.Show(Page1.RootPanel)

End Sub

Private Sub ashColor_Click(item As String)

    hd.ToastMessageShow(item, True)

End Sub

I see Delete but not cancel.  What happened?
 
Last edited:
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
How did you create the event routine for the action sheet?

I am having a problem getting my action sheet event routine to fire
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
the event routine uses (groupname defined in the initialize for routine)
B4X:
ashGroups.Initialize("ashGroups","Pick A Group","Cancel","",oGroupsList)
ashGroups.Show(ScrollViewInput.Panel)

...
B4X:
Private Sub ashGroups_Click(sItem As String)
    Dim arrElements() As String

    arrElements=Regex.Split("-",sItem)

    If arrElements.Length>0 Then

        sGlobalGroupId=arrElements(0)
        cmdGroup.Text=arrElements(1)
        sGlobalGroupIdText=arrElements(1)
        LoadTestIdValues
    EndIf

end sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…