Calling instance method in class method with Singleton
我已经读过在类方法中调用实例方法是使用单例方法的最佳方法。
我试过了,但没用。我试图调用
h
1 2 | + (void)normalizeCell:(UITableViewCell *)cell withLables:(NSArray *)lbls sx:(CGFloat)sx widths:(NSArray *)widths; - (void)edit; |
m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | + (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"); } |
在+方法中,不能将
代替
具有
当然,如果您的sharedmymanager是静态字段。并确保在调用该方法之前已初始化SharedmyManager。