ios - Delegate method is not called -


the problem delegate method not called. have code.

gridview.h

#import "editviewcontroller.h"  @protocol gridviewdelegate<nsobject> - (void)didselectcell:(uiview *)cell index:(nsuinteger)index; @end  @interface gridview : uiview<editviewdelegate>  @property (nonatomic, assign) id<gridviewdelegate> delegate;  @end 

gridview.m

@synthesize delegate;  - (void)handletap:(uigesturerecognizer *)gesturerecognizer {     nslog(@"handletap!");     if ([self.delegate respondstoselector:@selector(didselectcell:index:)])     {         [self.delegate didselectcell:gesturerecognizer.view index:0];     } } 

mainviewcontroller.h

#import "editviewcontroller.h" #import "gridview.h"  @interface mainviewcontroller : uiviewcontroller<gridviewdelegate> 

mainviewcontroller.m

- (void)viewdidload {     [super viewdidload];      [self.view addsubview:gridview];      gridview *gridview = [[gridview alloc]init];     gridview.delegate = self; }  - (void)didselectcell:(uiview *)cell index:(nsuinteger)index {     nslog(@"success!"); } 

when app build, handletap method called, self.delegate didselectcell not called.

when didselectcell method described in gridview.m, nslog correctly outputs success!

how fix call delegate method?

- (void)viewdidload {     [super viewdidload];      [self.view addsubview:gridview];      gridview *gridview = [[gridview alloc]init];     gridview.delegate = self; } 

after adding grid view view, create new grid view.
therefor have 2 grid views: 1 added view, 1 has delegate.

get rid of

gridview *gridview = [[gridview alloc]init]; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -