カスタムビューから.xibファイルを作成しました。そのビュー用に.h/.mファイルを作成しました。ボタンからヘッダーファイルにCtrlキーを押しながらドラッグして、IBActionを作成し、値をtouchUpInsideに設定しました。これが起こっていることです:
http://screencast.com/t/R1WTpK7xp
WTF?
upがボタンの外側にあるときにイベントをトリガーしますか?
編集:
スクリーンショットは次のとおりです。
そして、反対票のあるものは何ですか?その意味はわかりません。
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
問題がどこにあるのかわかりません。
編集2:
ボタンをアウトレットとして設定し、コードにターゲット/アクションを追加しようとしましたが、同じことが起こります。
.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;
}
編集3:ここに2つのビューを追加します。図面ビューはコードで作成され、bottomToolbarは.xibファイルから作成されます。
kBottomToolbarHeightは定数であり、.xibファイルで定義されている高さと同じ値です。
- (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;
}