Hello,

The IntPtr parameter does take a selector. With Monobjc, a selector
can be obtained from its string representation with the
ObjectiveCRuntime.Selector() method
(http://api.monobjc.net/html/M_Monobjc_ObjectiveCRuntime_Selector_1_72eac341.htm).

So you code needs to be changed to:

...
nsCountdown = 
NSTimer.ScheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats(1,
this, ObjectiveCRuntime.Selector("countdownTick:"), nsCountdown),
null, true);
...

Then define a public method CountdownTick() that is exposed to
Objective-C runtime:

[ObjectiveCMessage("countdownTick:")]  // <= The selector message is
the one used in the schedule method
public void CountdownTick(NSTimer theTimer)
{
    // Do the work here...
}

Hope it helps.

Regards, Laurent Etiemble.

2009/9/13  <[email protected]>:
> Hi,
>
> I'm trying to make an NSTimer which fires every second using:
>
> nsCountdown = 
> NSTimer.ScheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats(1, this, 
> countdownTick(), nsCountdown), null, true);
>
> Which builds fine if I make countdownTick() return an IntPtr, but it only 
> calls it once then I get errors saying:
>
> "-[MainWindow <null selector>]: unrecognized selector sent to instance"
>
> so I guess I need to specify a selector somehow, rather than just putting in 
> the name of the method I want called when the timer fires.
>
> I guess this has something to do with an IntPtr (as this is the type of the 
> variable I need to pass to the 
> 'ScheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats' Selector value) 
> or even an NSInvocation as there's another option of 
> 'ScheduledTimerWithTimeIntervalInvocationRepeats' that takes an invocation 
> instead of a target and selector.
>
> I know in Objective-C I would just use 'Self' as the target and 
> '@selector("countdownTick")' as the selector but what do I do in C#?
>
> Thanks,
>
> Russell
>
>

Reply via email to