I tried to use initWithFrame
but I am not able to display the UIView
, This kind of code solved many questions as I saw here but not in my case:
- (id)initWithFrame:(CGRect)frame myParams:(NSArray*)params;
.m file
- (id)initWithFrame:(CGRect)frame myParams:(NSArray*)params{ self = [super initWithFrame:frame]; if(self){ UIView *view = [UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; //Trying to send an uiview with gesture include view.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)]; [view addGestureRecognizer:tap]; [self addSubview:view]; } return self; }
Here is how I am trying to add the view in UIViewController
:
Maybe here I am doing it wrong, right?
Custom *view = [Custom alloc] initWithFrame:self.view.bounds myParams:array]; [self.view addSubview:view];
So, my question is it possible to add UITapGesture
in the UIView
generated in this class, cause it is not firing:
.h file
+ (UIView *)viewParams:(NSArray*)params;
.m file
+ (UIView *)viewWithParams:(NSArray*)params{ UIView *view = [UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; NSLog(@"read params %@", params); //Trying to send an uiview with gesture include view.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)]; [view addGestureRecognizer:tap]; return view; } - (void)test{ NSLog('it works...'); }
UPDATE : As instance method is working. But as class method I can not make it work. somebody know if possible?