IosMessageBox from Code?

Is there anyway to make IOSmessagebox come up using a method not immediately in the Actions for that view? There is a sample Xojo program, which “shows” it from a button directly on the window, so it only takes a line like “MyMessageWindow.show” to make it come up. Since I am gathering clicks from a canvas, that won’t work out. So I created a method that does the same code, but that does not work - neither MyMessageWindow nor View1.MyMessageWindow. The only way I can get it to come up at all, is to put the code in the OPEN action of the View canvas.

More generally, is there something like an IOSMessagebox but which allows text entry - something like this :
Preference Window
Company Name […box for data entry…]
Close button

[quote=397669:@Gregory Moore]More generally, is there something like an IOSMessagebox but which allows text entry - something like this :
Preference Window
Company Name […box for data entry…]
Close button[/quote]
Self.Pushto a new view. The user can use the automatic back button in the toolbar to return, or you can provide a Close button.

I’m having trouble understanding what you are trying to accomplish so I’m not certain my reply is relevant, but you can certainly call iOSMessageBox.Show from wherever you want such as from the PointerDown event of a Canvas.

This code in PointerDown uses a MessageBox to display the position of a tap on a Canvas (MessageBox1 was dragged onto the View):

MessageBox1.Message = "Tapped at " + pos.X.ToText + ", " + pos.Y.ToText MessageBox1.Show

Something like this ?

  1. Here is the original question again … this code is in the Xojo Documentation under “ios message box”
    HelloMessage.Title = “Hello”
    HelloMessage.Message = “Hello, World!”
    Dim buttons() As Text
    buttons.Append(“Yes”)
    buttons.Append(“No”)
    buttons.Append(“Maybe”)
    HelloMessage.Buttons = buttons
    HelloMessage.Show
    … and this works fine - but only if its called from within the window or view. However, I want to be able to call this from a module. And that does not seem to work.

  2. Regarding an additional text entry field, yes Jeremie Leroy, thats the kind of thing I wanted to add exactly. How to do it?

I dont work with “Xojo for iOS”, but in other iOS languages, the MessageBox (ie. Alert) but have a “parent” view in which to be presented. I would think that Xojo is requiring it to be called from within a window to satisfy that requirement

I could illustrate #2 very easily, just not in Xojo :slight_smile:

So are you using Xcode directly or something equivalent for Android? I always wondered if Xojo’s implementation left anything out - but I thought with the DECLARES, it didn’t.

In general, I find it easier to make modules to process various actions (e.g. a canvas Paint). Within the actual Paint action, it just calls an outside method in a module. In this way, I can develop fairly complicated clusters of methods and also find what I need to find easily rather than clicking around on various controls. This has worked well for me - but in this one case, it does not seem to work.

It seems that the new mini window is not being instantiated and appears not to exist. Whereas when you simply say “show” within the window code, it creates it and shows it.

Yes it leaves almost everything out… DECLARES should be used as the exception, not as the rule

Dave, we all know by now you hate Xojo for iOS. I don’t know why you keep answering questions saying it’s all broken and nothing is possible, but it’s not adding to helping Gregory.

Gregory, what you are trying to do is definitely possible. If you take a look at my iOSKit there is a module called “extensions” which has a function MsgBox. I recommend you take a look there for this because it is definitely possible (without declares even). I can answer any questions you have about what I did for that, or try to give more specific suggestions if you have any questions.

[quote=397860:@Gregory Moore]
2. Regarding an additional text entry field, yes Jeremie Leroy, thats the kind of thing I wanted to add exactly. How to do it?[/quote]
First you will need Jason King’s iOSKit: https://github.com/kingj5/iOSKit

Add a Property to your iOSView: Private Property alertController as UIKit.UIAlertController
In a button place this code:

[code] using UIKit
alertController = UIAlertController.AlertControllerWithTitleMessagePreferredStyle(“Title”, “Detail”, UIAlertController.UIAlertControllerStyle.Alert)

Dim block As new iOSBlock(AddressOf ConfigTextField)
alertController.AddTextField(block) //This code will be called directly by the UIAlertController just before displaying

Dim alert As UIAlertAction
alert = UIAlertAction.ActionWithTitleStyleHandler("Rename, UIAlertAction.UIAlertActionStyle.Default, WeakAddressOf alertHandler)
alertController.AddAction alert

alert = UIAlertAction.ActionWithTitleStyleHandler(“Cancel”, UIAlertAction.UIAlertActionStyle.Cancel, WeakAddressOf alertHandler)
alertController.AddAction alert

alertController.PresentInView(Self)[/code]

Add a method to your window:

[code]Private Sub ConfigTextField(textfield As ptr)
Declare Sub setText Lib UIKitLib selector “setText:” (obj_id As ptr, value As CFStringRef)
Declare Sub setPlaceholder Lib UIKitLib selector “setPlaceholder:” (obj_id As ptr, value As CFStringRef)
Declare Sub setSecureTextEntry Lib UIKitLib selector “setSecureTextEntry:” (obj_id As ptr, value As Boolean)

'Dim txtField As ptr = Foundation.NSObject.Allocate(NSClassFromString(“UITextfield”))

Dim txt, placeholder As Text, password As Boolean
txt = “Current Value”
placeholder = “Placeholder”
password = False

If txt.Empty = False Then
setText(textfield, txt)
End If
If placeholder.Empty = False Then
setPlaceholder(textfield, placeholder)
End If
If password Then
setSecureTextEntry(textfield, password)
End If

End Sub
[/code]

Add another method to your Window

[code]Private Sub alertHandler(sender as UIKit.UIAlertAction)
If sender.title = “Cancel” Then
alertController.Dismiss
Return
End If

If sender.title = “Rename”

Declare Function text_ Lib UIKitLib selector "text" (obj_id As ptr) As CFStringRef
Dim value As Text
Dim textfields As Foundation.NSArray = alertController.TextFields
Dim Fields() As Text
If textfields <> Nil Then
  For q As Integer = 1 To TextFields.count
    Dim field As ptr = TextFields.Value(q-1)
    fields.Append text_(field)
  Next
End If

value = Fields(0)

//Do something with the value returned by the Message Box

End If

alertController.Dismiss
End Sub
[/code]

Thank you. I am sorry to be slow to respond. I am trying to digest this.

I downloaded the kit but when I tried to open App.xojo.code, I got an error “The project manifest is missing required elements. The project may not have loaded as expected.” then I resolve some issue then it ran with a blank screen, and not doing anything apparently.

Perhaps I need to hire someone as a consultant to get me up to speed. I have been programming many years starting with Fortran IV, and various assembly languages (Vax11, Dec10, etc.) and even RealBasic for a number of years since 2003, but I am not sure how to get up to speed with no particular place to get instructions.

You should open iOSKit.xojo_project. Last I checked everything on github loaded properly. Please let me know if you continue to have issues with that.

Yes, it works fine - and has quite a few good examples of various things. Thanks!