Re: First trials in Cocoa app
Re: First trials in Cocoa app
- Subject: Re: First trials in Cocoa app
- From: Dave Carrigan <email@hidden>
- Date: Wed, 8 Sep 2010 21:12:49 -0700
You can't pass a method so you'll have to write a C function as your callback function. If the library allows you to pass a parameter to the function which will be in turn passed to the callback, then you would pass your view controller to the function and then call the method from the function. Your callback function would look something like
void callback(void* context)
{
[(MyViewController*) handleCallback];
}
If the library doesn't let you provide a context then you're probably stuck with saving your VC's address in a global variable that your callback can use.
Dave Carrigan
Seattle, WA
On Sep 8, 2010, at 1:21 AM, Remco Poelstra <email@hidden> wrote:
> Hi all,
>
> I'm very new to Cocoa and I'm trying to build my first app after reading and doing tutorials.
> I've a view with a UITextView on it and a button. When I press the button I want to call a third party C library which sends out and UDP packet searching for devices on the network. The responses of the devices are reported back with a callback that I've to supply.
> In the callback I want to store the string information in a NSMutableString and then update the UITextView with that string.
> I've a few problems: How can I pass a method from an object to the C library as callback? I'm currently using the NSViewController to define the method/callback.
> If that's not possible, how can I define a function that can reach the objects of my application? The ViewController is stored in the ApplicationDeletegate, but I can't find any reference to that object.
> I've defined the NSMutableString as a global in the viewcontroller header file, is that a good idea given the MVC design pattern?
> Hope someone can get me started on this one.
>
> Kind regards,
>
> Remco Poelstra
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden