3

I created a .xib file form my custom view. I created .h/.m files for that view. I ctrl dragged from button to header file to create an IBAction and set the value to touchUpInside. Here is what is happening:

http://screencast.com/t/R1WTpK7xp

WTF?

It triggers event when up is outside the button?

EDIT:

Here is the screenshot:

enter image description here

And what is the thing with down vote? I don't see a point in that.

View.h

#import <UIKit/UIKit.h>
#import "DrawingViewDelegate.h"

@interface DrawingBottomToolbarView : UIView

@property (weak) id <DrawingViewDelegate> delegate;

- (IBAction)lineSegmentButtonPush:(id)sender;

@end

View.m

#import "DrawingBottomToolbarView.h"

@implementation DrawingBottomToolbarView

@synthesize delegate;

- (id)initWithFrame:(CGRect)frame
{
    NSLog(@"frame");
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"DrawingBottomToolbarView" owner:self options:nil] objectAtIndex:0]];
        //[[[NSBundle mainBundle] loadNibNamed:@"DrawingBottomToolbarView" owner:self options:nil] objectAtIndex:0];
        //[self addSubview:self.];
    }

    return self;
}

//-(id)initWithCoder:(NSCoder *)aDecoder{
//    
//    NSLog(@"coder");
//    if ((self = [super initWithCoder:aDecoder])){
//        [self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"DrawingBottomToolbarView" owner:self options:nil] objectAtIndex:0]];
//    }
//    return self;
//}

- (IBAction)lineSegmentButtonPush:(id)sender 
{

     NSLog(@"line push");
}

@end

I don't get it where is the problem.

EDIT 2:

I tried setting buttons as outlets and add target/action in code and same thing happens:

.h

@property (weak, nonatomic) IBOutlet UIButton *lineSegmentButton;

.m

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"DrawingBottomToolbarView" owner:self options:nil] objectAtIndex:0]];
        self.currentSelectedPathSegment = NoneSegment;

        [self.lineSegmentButton addTarget:self action:@selector(lineSegmentButtonPush:) forControlEvents:UIControlEventTouchUpInside];

    }

    return self;
}

EDIT 3: Here is where I add two views. drawing view is created in code, bottomToolbar is created from .xib file.

kBottomToolbarHeight is constant with same value as height defined in .xib file.

- (void)viewWillAppear:(BOOL)animated
{
    [self.view addSubview:self.drawingView];
    [self.view addSubview:self.bottomToolbar];

    CGRect selfRect = self.view.bounds;
    CGRect drawingViewRect = selfRect;
    CGRect bottomToobarRect = selfRect;

    drawingViewRect.size.height = selfRect.size.height - kBottomToolbarHeight;
    bottomToobarRect.size.height = kBottomToolbarHeight;
    bottomToobarRect.origin.y = drawingViewRect.size.height;

    self.drawingView.frame = drawingViewRect;    
    self.bottomToolbar.frame = bottomToobarRect;    
}
vale4674
  • 4,161
  • 13
  • 47
  • 72
  • 1
    That probably means you hooked up the action wrong, do you have a screenshot of the connections inspector for the button? – Dan F Jul 19 '12 at 14:36
  • Hey, I edited question with screenshot. As you can see it is set on Touch Up Inside. – vale4674 Jul 19 '12 at 15:12
  • What happens if you add the action in code? – Dan F Jul 19 '12 at 15:24
  • Try deleting the button / outlet etc., clean project and start from scratch (i.e., make button/connections again) – Nicolas Miari Jul 19 '12 at 15:26
  • @ranReloaded I didn't set button as outlet, just an action. I'll edit question with code now. – vale4674 Jul 19 '12 at 16:56
  • I tried delete - clean - connect again, and same thing happens :S ?? – vale4674 Jul 19 '12 at 17:01
  • 1
    Nevertheless, setup an outlet to have access to the button. Then, in code, add target/action (as @Dan suggested) and see if it works... – Nicolas Miari Jul 19 '12 at 17:46
  • @ranReloaded I did try that and same thing happens. This is so strange. Could loading view from .xib be a problem? I really don't get it? – vale4674 Jul 19 '12 at 19:39
  • What happens if you connect the other two buttons touchUpInside with the action? – mAu Jul 19 '12 at 20:42
  • @mAu same thing happens, they both respond if touch is outside like shown in a video. – vale4674 Jul 20 '12 at 08:48
  • If these are standard (non-custom) UIButtons, try breaking it down into the simplest test case where this problem occurs, and if you find that case, submit a bug report to apple – Dan F Jul 20 '12 at 12:31
  • @DanF I tried in my other projects create a button and target/action in code and it works as expected. I tried adding button in storyboard (where using ViewController) and add button (and action) and it works. This thing that is not working for me is when I use only view (not view controller) and here button is acting this stupid. – vale4674 Jul 20 '12 at 12:43
  • Hmm, perhaps the way you are adding the view to your current hierarchy is to blame? Do you have some code surrounding that aspect that might shed some light on the issue? – Dan F Jul 20 '12 at 12:46
  • @DanF Look at my 3rd edit where I've put the code for adding subviews. – vale4674 Jul 20 '12 at 13:25
  • I realized that this happens if I init that view from code, I set it in IB as a subview of my controllers view, then `- (id)initWithCoder:` gets called and then it works normally. Strange. – vale4674 Jul 21 '12 at 13:11
  • This happens to me as well, only I create my view entirely from code and explicitly use UIControlEventTouchUpInside. No solution yet, but what I can add is that it works as expected in iOS 6, but not in iOS 5. – kaka Nov 09 '12 at 12:49

1 Answers1

0

The behavior you mention and show in the screencast is exactly the same as I experienced when I somewhere in the view hierarchy had a parent view with a UITapGestureRecognizer.

I'm unsure whether or not to flag your question as a possible duplicate of this one which helped me solve my problem.

For reference this is not a problem in iOS 6.0, only earlier versions.

Community
  • 1
  • 1
kaka
  • 1,158
  • 1
  • 13
  • 15
  • This was happening when I was combining Interface Builder (Storyboard) and code. After I defined everything in code I got everything working again. The thing you are mentioning with `UITapGestureRecognizer` could just be the cause because I am having it also. I'll accept yours answer since it is very likely that that recognizer was causing that. – vale4674 Nov 12 '12 at 07:54