Lilz
Lilz

Reputation: 4091

Delegates and protocols objective c

I followed on some advice given on this very forum and I am still having difficulty

I have the following:

    #import <UIKit/UIKit.h>


    @protocol UIViewForWheelProtocol

    - (void) returnImageNumber:(int)imgNum;

    @end


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


    @interface UIViewForWheel : UIView {
        id<UIViewForWheelProtocol> delegate;
    }

    @property (nonatomic, assign) id<UIViewForWheelProtocol> delegate;



    @implementation UIViewForWheel

    @synthesize delegate;

    -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
       int num =1 ;
       [self.delegate returnImageNumber:num];
    }

#import <UIKit/UIKit.h>
#import "UIViewForWheel.h"
#import "UIViewForWheelProtocol.h"


@interface MainMenu : UIViewController <UIViewForWheelProtocol> {

}

-(void) returnImageNumber:(int)whichImage;

@end


    #import "MainMenu.h"


    @implementation MainMenu

    - (void) returnImageNumber:(int)whichImage
    {
        NSLog(@"HI %i", whichImage);
    }

HI 1 is not being displayed because although it is going to the touchesMoved function it is not going to the returnImageNumber in the MainMenu class.

Can someone please explain what I am doing wrong please?

Upvotes: 1

Views: 962

Answers (1)

Richard J. Ross III
Richard J. Ross III

Reputation: 55583

Ensure that you have manually assigned the delegate for UIViewForWheel, and that MainMenu conforms to that protocol UIViewForWheelProtocol.

Upvotes: 4

Related Questions