iOS declare help for popover

I’ve been trying to get a popover to work but obviously don’t know what I’m doing when it comes to declares. Any help would be appreciated.

I created a method CreatePopover(inView As Ptr, popView As Ptr) that I call from a button action event:

[code] Dim vSelect As New SelectView

CreatePopover(Self.Handle, vSelect.Handle)
[/code]

The CreatePopover has the following code. (Note that this isn’t intended to be the final code, I’m just trying to get it to work.)

[code] Declare Function NSClassFromString Lib “Foundation” (classname As CFStringRef) As Ptr
Declare Function alloc Lib “Foundation” selector “alloc” (classRef As Ptr) As Ptr

Dim vPtr_SelectClass As Ptr = NSClassFromString(“UIPopoverController”)
Dim vPtr_Select As Ptr = alloc(vPtr_SelectClass)

// Init code
Declare Sub InitSelect Lib “UIKit” selector “initWithContentViewController:” (id As Ptr, viewController As Ptr)
InitSelect(vPtr_Select, popView)

Declare Sub DisplaySelect Lib “UIKit” selector “presentPopoverFromRect:inView:permittedArrowDirections:animated:” (displayRect As CGRect, inView As Ptr, arrowDir As UIPopoverArrowDirection, animated As Boolean)
Dim frame As CGRect
Dim frameOrigin As CGPoint
Dim frameSize As CGSize
frameOrigin.x = 0
frameOrigin.y = 0
frameSize.height = 200
frameSize.width = 100
frame.origin = frameOrigin
frame.mysize = frameSize

DisplaySelect(frame, inView, UIPopoverArrowDirection.UIPopoverArrowDirectionAny, True)
[/code]

When I run this and tap the button the code runs but nothing happens. If I change the x and y in the frameOrigin to anything other than 0,0 the application crashes.

Am I going about this in the right way, am I even close? Or do I need to be creating a class that I drag onto my view? If this is the case then can you please suggest an example I can study to learn how this is done. I have been looking at examples that use declares but have not gotten it right and don’t know what the correct way is.

Thanks.

@jean-paul devulder has a PopOver control in his iOS plugins: dethomsoft .

Thanks for the suggestion, I did look at this plugin, but I would prefer to not use a plugin and write the declares needed. Is it a much bigger job than appears so not easy to answer my initial question?

A few things right off the bat - most importantly, you are missing the implicit self object in your declares which is why nothing is happening. initSelect should be a function (not a sub) and must return a pointer. Similarly you need to add a new first parameter to your display select declare and pass the object returned by the initSelect function. Also, depending on how you have declared CGRect/CGPoint/CGSize this code won’t work on either 64bit or 32bit (you need two completely different structures for each architecture). Also as far as I know popovers only work on iPads. There may be other errors as well that I didn’t see in a quick glance. I suggest you look at iOSKit or MacOSLib to see how objective-c objects are initiated and used in Xojo declares.

Thanks for the comments, I appreciate it. It helps to have something to point me in the right direction. Where I was planning on using popovers will only appear if running on an iPad so I don’t need them for when the app is running on an iPhone. I hadn’t caught about the 32/64bit so I will look into that more.

Hello ,
I want to display popover on button action event using declare .
Can I get example project for it?