我做了我的研究,但還沒有找到對以下問題的答案:我有一個自定義委託-subclass UIView-由於某種原因touchesBegan不工作在委託實現中。自定義UIView委託沒有檢測到touchesBegan
TestView.h
#import <UIKit/UIKit.h>
@class TestView;
@protocol TestViewDelegate <NSObject>
@end
@interface TestView : UIView
@property (assign) id <TestViewDelegate> delegate;
@end
TestView.m
#import "TestView.h"
@implementation TestView
@synthesize delegate = _delegate;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Touch detected on TestViewDelegate");
}
@end
ViewController.h
#import <UIKit/UIKit.h>
#import "TestView.h"
@interface ViewController : UIViewController<TestViewDelegate>
@end
ViewController.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel* title = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 280, 40)];
[title setFont:[UIFont fontWithName:@"Helvetica-Bold" size:30]];
[title setTextColor:[UIColor blackColor]];
[title setTextAlignment:UITextAlignmentCenter];
[title setBackgroundColor:[UIColor clearColor]];
[tile setText:@"Test"];
[self.view addSubview:title];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
@end
我缺少什麼,以確保從TestView.m touchesBegan
當觸摸發生在ViewController.m被調用?
您錯過了主要部分 - 您需要創建並使用TestView以使其正確 – beryllium 2012-04-01 20:50:32
實現是錯誤的。請檢查文檔和示例 – Legolas 2012-04-01 20:51:54