나는 두 번째 샘플 코드 인 iphone developmenst에서 초보자입니다. 뷰에 하위 뷰를 추가하고 터치 한 뷰에 따라 이벤트를 생성하려고합니다. 내가 새로 만든 깨끗한 창 - 기본 응용 프로그램이 실험하고있는 프로젝트는 subviews 터치 이벤트를 얻고 그에 따라 적절한 조치를 위임하는 방법
나는 하나에 다음 코드를 썼습니다 만의 ViewController의 코드 :@interface testViewController : UIViewController {
IBOutlet UIView *redView;
IBOutlet UIView *redView1;
IBOutlet UIView *blueView;
}
//---expose the outlet as a property---
@property (nonatomic, retain) IBOutlet UIView *redView;
@property (nonatomic, retain) IBOutlet UIView *redView1;
@property (nonatomic, retain) IBOutlet UIView *blueView;
//---declaring the action---
-(IBAction) viewClicked: (id) sender;
@end
하고하는 .m 파일이 동작 응답자를 포함 내가 무엇을하려고하는지는 내 견해를 건 드리면 그에 따라 redview의 배경색을 변경하는이 단일 메서드로 처리해야하는 이벤트를 생성합니다.
-(IBAction) viewClicked:(id) sender {
redView.backgroundColor = [UIColor blackColor];
}
은 내가 testAppdelegate.mi에서
@interface testAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
testViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet testViewController *viewController;
@end
는 전망하고 여기에 accoring에 파단을 만드는 중이라서 그들은 매우 잘 표시되어있다하지만 난 그것에 이벤트를 얻을 수 없습니다 나는이 방법으로 대리자를 worte 그들이 (viewClicked :) 메서드에 닿았을 때. 이것을하는 방법 ????
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.backgroundColor = [UIColor whiteColor];
// Create a simple red square
CGRect redFrame = CGRectMake(0, 10, 320, 100);
UIView *redView = [[UIView alloc] initWithFrame:redFrame];
redView.backgroundColor = [UIColor redColor];
//-------------------------------------------------------------------------------------------------------
// Create a simple blue square
CGRect blueFrame = CGRectMake(5, 115, 100, 100);
UIView *blueView = [[UIView alloc] initWithFrame:blueFrame];
blueView.backgroundColor = [UIColor blueColor];
// Create a simple blue square
CGRect blueFrame1 = CGRectMake(110, 115, 100, 100);
UIView *blueView1 = [[UIView alloc] initWithFrame:blueFrame1];
blueView1.backgroundColor = [UIColor blueColor];
// Add the square views to the window
[window addSubview:redView];
[window addSubview:blueView];
[window addSubview:blueView1];
[window addSubview:viewController.redView];
[window addSubview:viewController.blueView];
[window addSubview:viewController.blueView1];
[window makeKeyAndVisible];
}
감사
: 일반적으로 접촉을 처리하기 위해, 당신은 touchesBegan를 사용합니다. – Jacob