0

Ok, so this has been driving me mad for a while, but it occasionally self corrects so I've dealt with it, but it's time to fix it!

Situation is as follows:

View created in Interface Builder for iOS. Contains a UIButton referenced as 'banana015'

Method in my implementation .m as follows:

- (IBAction)draggedOut: (id)sender withEvent: (UIEvent *) event {

    if ([[NSUserDefaults standardUserDefaults] integerForKey:@"edittingmode"] == 3) {

    UIButton *selected = (UIButton *)sender;
    selected.center = [[[event allTouches] anyObject] locationInView:self.view];
        if ([[NSUserDefaults standardUserDefaults] integerForKey:@"changeskin"] == 1) {
            [self scifiTempSave];
        }
        else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"changeskin"] == 2) {
            [self bananaTempSave];
        }
        else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"changeskin"] == 3) {
            [self orangeTempSave];
        }
    }
    else{}

} 

And declared in my .h Header as

-(IBAction)draggedOut:(id)sender;

Now, when I connect the button to the 'draggedOut:' method in Interface Builder using the Touch Drag Inside event, I can drag the button around when I build and run the project (expected behaviour) however when I release the app crashes.

In the past I've been able to connect to a method that appears as "draggedout: withevent" which works beautifully. This evening I've connected some 50 items up to this 'draggedout: withevent' option and it works beautifully for each one - I have however got two UIButtons (identical in almost every way (different referencing outlets) that I have yet to connect to it, and I'll be damned if it'll let me.

Can anyone help? This has been infuriating for some time. The option disappears, yet all those that I previously connected to it still work perfectly, I just can't hook anything new up to it...or the old ones if I disconnect them.

David26th
  • 401
  • 2
  • 12
  • 26
  • The one problem I can see here is that your method declaration in the header is different than the implementation. – Tom Hamming Aug 05 '11 at 20:25
  • How should I be declaring it in the header? – David26th Aug 05 '11 at 20:25
  • `- (IBAction)draggedOut: (id)sender withEvent: (UIEvent *) event;` Also please post whatever error info you can about the crash that happens when you release the button. If you haven't already, [enable NSZombieEnabled](http://stackoverflow.com/questions/2190227/how-do-i-set-nszombieenabled-in-xcode-4) – Tom Hamming Aug 05 '11 at 20:28
  • Actually just realised the crash was occurring for reasons unrelated to this particular issue (a typo - just coincidentally fell on the same button) Thanks for the help - it seems to have sorted my issue, I still get the option to connect to a simple draggedout: method as well though - any idea why I'd get both (and if you'd care to put your comments in the form of an answer I'd happily tick it for you :) – David26th Aug 05 '11 at 20:38

1 Answers1

1

The one problem I can see is that your method declaration in the header is not the same as your implementation. The header declaration should be the first line of the method in the implementation plus a semicolon:

- (IBAction)draggedOut: (id)sender withEvent: (UIEvent *) event;

To get more info on the crash, you should try setting NSZombieEnabled to true.

To answer your question in the comment, I don't know why you would get the option of a draggedout: method in addition to the one including withEvent if it's not declared in your code.

Community
  • 1
  • 1
Tom Hamming
  • 10,577
  • 11
  • 71
  • 145