WFCThemeTableViewController.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // WFCThemeTableViewController.m
  3. // WildFireChat
  4. //
  5. // Created by dali on 2020/4/11.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCThemeTableViewController.h"
  9. #import "UIColor+YH.h"
  10. #import "WFCThemeTableViewCell.h"
  11. #import <WFChatUIKit/WFChatUIKit.h>
  12. @interface WFCThemeTableViewController () <UITableViewDataSource, UITableViewDelegate>
  13. @property (nonatomic, strong)UITableView *tableView;
  14. @end
  15. @implementation WFCThemeTableViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. CGRect frame = self.view.frame;
  19. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
  20. if (@available(iOS 15, *)) {
  21. self.tableView.sectionHeaderTopPadding = 0;
  22. }
  23. self.tableView.delegate = self;
  24. self.tableView.dataSource = self;
  25. self.tableView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  26. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  27. self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  28. self.tableView.tableHeaderView = nil;
  29. self.definesPresentationContext = YES;
  30. self.tableView.sectionIndexColor = [UIColor colorWithHexString:@"0x4e4e4e"];
  31. [self.view addSubview:self.tableView];
  32. [self.tableView reloadData];
  33. }
  34. - (void)displayUpdatedAlert {
  35. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"修改成功!请退回到应用主页面查看效果。" preferredStyle:UIAlertControllerStyleAlert];
  36. UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  37. }];
  38. [alert addAction:action2];
  39. [self presentViewController:alert animated:YES completion:nil];
  40. }
  41. #pragma mark - UITableViewDataSource
  42. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  43. return 2;
  44. }
  45. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  46. WFCThemeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  47. if (!cell) {
  48. cell = [[WFCThemeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  49. }
  50. if (indexPath.row == ThemeType_WFChat) {
  51. cell.textLabel.text = @"蓝色";
  52. } else if(indexPath.row == ThemeType_White) {
  53. cell.textLabel.text = @"白色";
  54. }
  55. if ([WFCUConfigManager globalManager].selectedTheme == indexPath.row) {
  56. cell.checked = YES;
  57. } else {
  58. cell.checked = NO;
  59. }
  60. return cell;
  61. }
  62. #pragma mark - UITableViewDelegate
  63. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. return 48;
  65. }
  66. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  67. if (indexPath.row != [WFCUConfigManager globalManager].selectedTheme) {
  68. [WFCUConfigManager globalManager].selectedTheme = indexPath.row;
  69. [self.tableView reloadData];
  70. [self displayUpdatedAlert];
  71. }
  72. }
  73. @end