我在这个论坛上给出了一些建议,我仍然遇到了困难
我有以下内容:
#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未显示,因为虽然它将转到touchesMoved函数,但它不会转到MainMenu类中的returnImageNumber。
有人可以解释一下我做错了吗?
答案 0 :(得分:4)
确保您已为UIViewForWheel
手动分配了代理,MainMenu
符合该协议UIViewForWheelProtocol
。