简体   繁体   中英

How to programmatically set custom class?

I use -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event in my view controller to get touches on view handled by the view controller. But is it possible to use this same method on a sub view added on the view handled by this view controller to get touches from it?

I have tried to create .m and .h files for such views so that I can get touches there using the -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event method but that only work if I set the custom class in the storyboard but is not possible as the view was made programmatically. So is it possible to some way set the custom class in my mainViewController itself. So the compiler knows what view this .m and .h files are associated?

I know there are other methods like -hitTest: and tap gesture recognizers but i am interested in -touchBegan:

Thanks for looking :)

Of course you can assign a custom class without storyboard.

CustomView *customView = [[CustomView alloc] initWithFrame:theFrame];
[self.view addSubview:customView];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM