La mise en œuvre de délégué méthodes modale-vue-contrôleur de transfert de données

J'ai un projet simple de présenter un modal-vue-contrôleur et de transférer une chaîne basée sur le bouton modale des VC qui se pressé. Je me suis basé sur regarder le cours à Stanford sur iTunes U. Il semble que j'ai tout corriger, mais je reçois un couple des avertissements du compilateur.

J'obtiens d'abord appelé passing argument 1 of 'setDelegate:' from incompatible pointer type dans TransferViewController.m

Deuxième-je obtenir quatre avertissements appelé Invalid receiver type 'id <MyModalViewControllerDelegate>*' mais ce ne sont pas affichées dans les résultats de la compilation de la zone, plutôt à côté de la délinquance des lignes dans MyModalViewController.m, les deux lignes dans chacune des actions de bouton.

Voici le code...

// TransferViewController.h

#import <UIKit/UIKit.h>
#import "MyModalViewController.h";

@interface TransferViewController : UIViewController <MyModalViewControllerDelegate> {
    UILabel *label;
    UIButton *button;
}

@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) UIButton *button;

- (IBAction)updateText;

@end

// TransferViewController.m

#import "TransferViewController.h"

@implementation TransferViewController

@synthesize label;
@synthesize button;

- (IBAction)updateText {
    MyModalViewController *myModalViewController = [[MyModalViewController alloc] init];
    myModalViewController.delegate = self; //I get the warning here.
    [self presentModalViewController:myModalViewController animated:YES];
    [myModalViewController release];
}

- (void)myModalViewController:(MyModalViewController *)controller didFinishSelecting:(NSString *)selectedDog {
    label.text = selectedDog;
    [self dismissModalViewControllerAnimated:YES];
}

@end

// MyModalViewController.h

#import <UIKit/UIKit.h>

@protocol MyModalViewControllerDelegate;

@interface MyModalViewController : UIViewController {
    UIButton *abby;
    UIButton *zion;
    id <MyModalViewControllerDelegate> delegate;
}

@property (assign) id <MyModalViewControllerDelegate> delegate;

- (IBAction)selectedAbby;
- (IBAction)selectedZion;

@end

@protocol MyModalViewControllerDelegate <NSObject>

@optional

- (void)myModalViewController:(MyModalViewController *)controller didFinishSelecting:(NSString *)selectedDog;

@end

// MyModalViewController.m

#import "MyModalViewController.h"

@implementation MyModalViewController

@synthesize delegate;

- (IBAction)selectedAbby {
    if ([self.delegate respondsToSelector:@selector (myModalViewController:didFinishSelecting:)]) {
        [self.delegate myModalViewController:self didFinishSelecting:@"Abby"];
    }
}

- (IBAction)selectedZion {
    if ([self.delegate respondsToSelector:@selector (myModalViewController:didFinishSelecting:)]) {
        [self.delegate myModalViewController:self didFinishSelecting:@"Zion"];
    }

}

OriginalL'auteur Steve | 2010-07-16