Looking to replace a complex mobilemessagebox with a popover containing various buttons.
I downloaded the Xojo popover example, and their popovers can be either a screen or container.
When they appear, they are pretty sizable - certainly different to the size at design time.
In my own project, I created a dummy screen with a few buttons, and tried the sample code.
However, I just get a tiny popover , and I see no way to control its size.
Does this only work properly on iPhone / portrait layouts?
As an alternative, if you have iOSKit in your project, you can use action sheets:
using UIKit
alertController = UIAlertController.AlertControllerWithTitleMessagePreferredStyle(me.Items(index).title, "", UIAlertController.UIAlertControllerStyle.ActionSheet)
dim alert as UIAlertAction
//actions is a text array containing the name of each action
Dim actions() as Text
actions.Add "Action 1"
actions.Add "Action 2"
For each action as text in actions
alert = UIAlertAction.ActionWithTitleStyleHandler(action, UIAlertAction.UIAlertActionStyle.Default, WeakAddressOf alertHandler)
alertController.AddAction alert
Next
//Cancel button
alert = UIAlertAction.ActionWithTitleStyleHandler("Cancel", UIAlertAction.UIAlertActionStyle.Cancel, WeakAddressOf alertHandler)
alertController.AddAction alert
if isIPad then
Dim x As Integer = (me.Width/(me.items.LastIndex+1) * index) //me is the MobileUIControl that was clicked to display the popover
alertController.PresentInPopover(self, me, new Foundation.NSRect(x, 0, me.Width, me.Height))
Else
alertController.PresentInView(self)
end if
with isiPad method
Private Function isIPad() As Boolean
#if TargetIOS
Declare Function NSClassFromString Lib "Foundation" (name As CFStringRef) As Ptr
declare function currentDevice_ lib "UIKit" selector "currentDevice" (clsRef as ptr) as ptr
declare function model_ lib "UIKit" selector "model" (obj_id as ptr) as CFStringRef
dim model as Text = model_(currentDevice_(NSClassFromString("UIDevice")))
dim isPad as boolean = model.BeginsWith("iPad")
Return isPad
#endif
End Function
And alertHandler method
Private Sub alertHandler(sender as UIKit.UIAlertAction)
//Cancel button
if sender.title = "Cancel" then
Return
end if
Dim action As Text = sender.title
//Do something depending on action
...
End Sub
Hi Jeremie, how can you solve this with a modal screen so that it only half covers the screen below and can still be resized? Unfortunately, I have only ever been able to solve this with full modal screens. Thank you - would help me a lot.
I’ve just tested a container as a child of the window.
I make it visible or not as I need, and I disable the area behind it, (as for some reason the unused area of the container allows pointer actions to propagate through.)
I’m sure there is a better solution using the modal window approach, but Im still playing at the moment
Var s as New ScreenSheet //the modal screen you want to show
Var showGrabber as Boolean = True
Var animate As Boolean = True
Var radius as Double = 18
s.ShowSheetXC(self, ViewExtensionsXC.UISheetPresentationControllerDetent.medium_large, showGrabber, animate, radius)
And it will display a half sized popup like this, that can be “maximised” by dragging it to the top.
Hi Jeremy, that really helps me a lot, I’ll try it out soon. I’ve been looking for a solution like this for a long time and didn’t know exactly how to implement it.
Hi Jeremie, thank you for this solution. Works perfectly. On StackOverflow I read that it is also possible to set custom detents, but I have no idea how to implement this. Could you add this to your example?