0

I'm using CPJoystick which can be found here. https://github.com/Wense/CPJoystick

I'm using Xcode 4.6 and the breakpoint stops over there.

@property (nonatomic, weak,   readwrite) id<CPJoystickDelegate> delegate;

So I made little changes. I have download hundreds of delegate and even try this one: Custom delegate not working

I've tried many:

@property (nonatomic, strong, readwrite) id<CPJoystickDelegate> delegate;
@property (nonatomic, strong) id<CPJoystickDelegate> delegate;
@property (nonatomic, retain) id<CPJoystickDelegate> delegate;
@property(nonatomic,assign)id delegate;

I don't understand what I doing. I'm stuck and confused about five weeks.

CPJoystick.h

@protocol CPJoystickDelegate <NSObject>
@required
- (void) ShowthisNumbers:(NSString*)text;
@optional
// - (void) ShowthisNumbers:(NSString*)text;
-(void)cpJoystick:(CPJoystick *)aJoystick didUpdate:(CGPoint)movement;
@end

CPJoystick.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
     ...
     [delegate ControlPosition:@"Touched"];

}

I can't even make this thing communicate UILabel on UIViewController < CPJoystickDelegate > The joystick seems to work fine but the UILabel isn't working.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    CPJoystick *joystick = [[CPJoystick alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [joystick setThumbImage:[UIImage imageNamed:@"handleImage.png"] andBGImage:[UIImage imageNamed:@"bgImage.png"]];

    [joystick setMovementUpdateInterval:1.0/30];
    [self.iSneaky addSubview:joystick];
    [joystick setMoveViscosity:4 andSmallestValue:0.09]; //defaults are 7 and 0.09


}
-(void)ControlPosition:(NSString*)text;
{

    amountLabel.text = text;
}

-(void)cpJoystick:(CPJoystick *)aJoystick didUpdate:(CGPoint)movement                                
{
NSLog(@"x = %f",movement.x);
NSLog(@"y = %f",movement.y);                                                                                                    
    character.center = CGPointMake(character.center.x + movement.x, character.center.y +     movement.y);
}   

Can anyone help me.... I need to some fresh air.

4

1 回答 1

0

您似乎没有在您的方法中设置委托。viewDidLoad

CPJoystick *joystick = [[CPJoystick alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[joystick setThumbImage:[UIImage imageNamed:@"handleImage.png"] andBGImage:[UIImage imageNamed:@"bgImage.png"]];

[joystick setMovementUpdateInterval:1.0/30];
[self.iSneaky addSubview:joystick];
[joystick setMoveViscosity:4 andSmallestValue:0.09]; //defaults are 7 and 0.09
joystick.delegate = self;
于 2013-04-25T15:53:20.220 回答