I have read about calling instance method in class method is the best way with Singleton.
I have tried it but it didn't work. I am trying to call the void method in @selector()
but I couldn't. Please where would be my issue?
.H
+ (void)normalizeCell:(UITableViewCell *)cell withLables:(NSArray *)lbls sx:(CGFloat)sx widths:(NSArray *)widths;
- (void)edit;
.M
+ (void)normalizeCell:(UITableViewCell *)cell withLables:(NSArray *)lbls sx:(CGFloat)sx widths:(NSArray *)widths
{
static PozisyonOzetiTableCell *sharedMyManager = nil;
static BOOL initialized = NO;
if(!initialized)
{
initialized = YES;
sharedMyManager = [[PozisyonOzetiTableCell alloc] init];
}
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//// I have tried edit & [sharedMyManager edit]
[button addTarget:self action:@selector(edit) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"settingKey.png"] forState:UIControlStateNormal];
button.frame = CGRectMake(-23, 0, 70, 40);
[cell.contentView addSubview:button];
}
- (void)edit
{
NSLog(@"CLICKED");
}
In + method you can't use self
for that puspose, because self
in class method returns Class
and not the instance.
replace
[button addTarget:self action:@selector(edit) forControlEvents:UIControlEventTouchUpInside];
with
[button addTarget:sharedMyManager action:@selector(edit) forControlEvents:UIControlEventTouchUpInside];
Of course , if your sharedMyManager is static field. And make sure that your sharedMyManager was already initialized before calling that method.