• 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
help with delegates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

help with delegates


  • Subject: help with delegates
  • From: albert jordan Mobility <email@hidden>
  • Date: Fri, 27 Mar 2009 10:30:26 -0700




I am having problems with implementing delegates, and I'm sure I'm doing something silly.  Would appreciate help from the experts here.....  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"];
}

}


would appreciate any help.

regards,

Albert

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: help with delegates
      • From: David Dunham <email@hidden>
  • Prev by Date: Re: Xcode, Cocoa and std::list
  • Next by Date: Re: Xcode, Cocoa and std::list
  • Previous by thread: Re: Xcode, Cocoa and std::list
  • Next by thread: Re: help with delegates
  • Index(es):
    • Date
    • Thread