NIMKitSwitcherCell.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // NTESSettingPushNotifySwitcherCell.m
  3. // NIM
  4. //
  5. // Created by chris on 15/6/26.
  6. // Copyright © 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMKitSwitcherCell.h"
  9. #import "NIMCommonTableData.h"
  10. #import "UIView+NIM.h"
  11. @interface NIMKitSwitcherCell ()
  12. @end
  13. @implementation NIMKitSwitcherCell
  14. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  15. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  16. if (self) {
  17. _switcher = [[UISwitch alloc] initWithFrame:CGRectZero];
  18. [self addSubview:_switcher];
  19. }
  20. return self;
  21. }
  22. - (void)refreshData:(NIMCommonTableRow *)rowData tableView:(UITableView *)tableView{
  23. self.textLabel.text = rowData.title;
  24. self.detailTextLabel.text = rowData.detailTitle;
  25. NSString *actionName = rowData.cellActionName;
  26. [self.switcher setOn:[rowData.extraInfo boolValue] animated:NO];
  27. [self.switcher removeTarget:self.nim_viewController action:NULL forControlEvents:UIControlEventValueChanged];
  28. if (actionName.length) {
  29. SEL sel = NSSelectorFromString(actionName);
  30. [self.switcher addTarget:tableView.nim_viewController action:sel forControlEvents:UIControlEventValueChanged];
  31. }
  32. }
  33. #define SwitcherRight 15
  34. - (void)layoutSubviews{
  35. [super layoutSubviews];
  36. self.switcher.nim_right = self.nim_width - SwitcherRight;
  37. self.switcher.nim_centerY = self.nim_height * .5f;
  38. }
  39. @end