• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: Help with implementing delegates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Help with implementing delegates


  • Subject: Fwd: Help with implementing delegates
  • From: albert jordan Mobility <email@hidden>
  • Date: Fri, 27 Mar 2009 16:01:48 -0700




I am having problems with implementing delegates, and I'm sure I'm doing something silly. Would appreciate help from the experts..... I can get a simple case to work, where I invoke a delegate method with no parameters passed, but I can't get the case where I invoke the delegate method and want to pass an additional object (or flag).

I've written small program to illustrate my problem. I have two classes, say Foo and Bar. The code allows a user to push a button on a screen, which starts a process in Foo (a controller type class). Foo starts a progress bar item on the screen, and calls a method in class Bar (model class). The method in Bar fires up a timer (NSTimer) and returns immediately. When the timer expires, I want to communicate to class Foo that the event was completed.

I am using a design pattern that was available online, and for the most part everything seems to be working. In the code below, I fail the condition where I check to see if "_delegate" responds to the selector (test:didFinish:).

- (void) doneWithTimer: (NSTimer *) aTimer
{

	NSLog(@"Bar: time over....");

	if ([_delegate respondsToSelector:@selector(test:didFinish:)  ])
	{
		[_delegate test: self didFinish: true];
	}
	else
	{
		[NSException raise:NSInternalInconsistencyException
					format:@"Foo doesn't respond to selector"];
	}

}	


If I have a simple method with no additional parameters, the code works fine. So, the following works....


- (void) doneWithTimer: (NSTimer *) aTimer
{

	NSLog(@"Bar: time over....");

	if ([_delegate respondsToSelector:@selector(test:)  ])
	{
		[_delegate test: self];
	}
	else
	{
		[NSException raise:NSInternalInconsistencyException
					format:@"Foo doesn't respond to selector"];
	}

}	


In Foo, I have set up the following delegate method

-(void) test: (dgtest *) sender:didFinish: (BOOL) complete
{
	NSLog(@"time over....%d");
	[progress stopAnimation:nil];
}

(and of course if I drop ":didFinish: (BOOL) complete", and run the program passing no parameters then delegates seem to work).

would appreciate any help.

regards,

Albert

____

_______________________________________________

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


References: 
 >Help with implementing delegates (From: albert jordan Mobility <email@hidden>)

  • Prev by Date: Can NSTrackingArea rects be nested?
  • Next by Date: Popup menu in custom view ...
  • Previous by thread: Help with implementing delegates
  • Next by thread: Re: Help with implementing delegates
  • Index(es):
    • Date
    • Thread