Having trouble with delegates

Discussion in 'iOS Programming' started by tombuarts, Oct 23, 2010.

  1. tombuarts macrumors newbie

    Joined:
    Jan 30, 2010
    #1
    I have a view called BlueView that calls a modal view called DatePick. When DatePick is dismissed by pressing a button I would like it to call a method in BlueView. Heres what I have so far:

    In BlueViewController.h;

    Code:
    @protocol dateset
    -(void)calculate; 
    @end
    
    @interface BlueViewController : UIViewController <dateset> {
    	id <dateset> delegate;
    (other code here)
    
    @property(assign)id<dateset>delegate;
    
    In BlueViewController.m

    Code:
    @synthesize delegate;
    
    -(void)calculate {
    (the method I would like to be called)
    
    In DatePickController.m

    Code:
    - (IBAction) selectButtonPressed:(id)sender {
    	chooseDate = [datePicker date];
    	gotnewdate = 1;
    	[delegate calculate];
    
    At this point I am getting an error in DatePickController.m saying that "delegate" is undeclared. Any thoughts would be appreciated. Also, if you think there are other things missing, please let me know.
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    If delegate is undeclared, then you need to declare it.

    In this case, it's worth considering why class DatePickController can/cannot refer to a variable in class BlueViewController.
     
  3. tombuarts thread starter macrumors newbie

    Joined:
    Jan 30, 2010
    #3
    Ok, I declared delegate as an NSObject, and now I get an error stating "NSObject may not respond to -calculate". Any ideas?
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    You're in over head. Stop, go back, review the basics.

    If you're using a book, go back and work through the previous example or exercise.

    If you're using an online tutorial, do the same thing.

    If you're not using a book or online tutorial, then what you have is someone who doesn't know Objective-C trying to teach Objective-C. Would you take a class from someone who didn't understand what they were teaching?
     
  5. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #5
    Why did you declare 'delegate as an NSObject'? Why do you think NSObject should respond to your own method 'calculate:'?
     

Share This Page