2
0

WFCThemeTableViewController.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. self.tableView.delegate = self;
  21. self.tableView.dataSource = self;
  22. self.tableView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  23. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  24. self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  25. self.tableView.tableHeaderView = nil;
  26. self.definesPresentationContext = YES;
  27. self.tableView.sectionIndexColor = [UIColor colorWithHexString:@"0x4e4e4e"];
  28. [self.view addSubview:self.tableView];
  29. [self.tableView reloadData];
  30. }
  31. - (void)displayUpdatedAlert {
  32. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"修改成功!请退回到应用主页面查看效果。" preferredStyle:UIAlertControllerStyleAlert];
  33. UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  34. }];
  35. [alert addAction:action2];
  36. [self presentViewController:alert animated:YES completion:nil];
  37. }
  38. #pragma mark - UITableViewDataSource
  39. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  40. return 2;
  41. }
  42. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  43. WFCThemeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  44. if (!cell) {
  45. cell = [[WFCThemeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  46. }
  47. if (indexPath.row == ThemeType_WFChat) {
  48. cell.textLabel.text = @"蓝色";
  49. } else if(indexPath.row == ThemeType_White) {
  50. cell.textLabel.text = @"白色";
  51. }
  52. if ([WFCUConfigManager globalManager].selectedTheme == indexPath.row) {
  53. cell.checked = YES;
  54. } else {
  55. cell.checked = NO;
  56. }
  57. return cell;
  58. }
  59. #pragma mark - UITableViewDelegate
  60. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  61. return 48;
  62. }
  63. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  64. if (indexPath.row != [WFCUConfigManager globalManager].selectedTheme) {
  65. [WFCUConfigManager globalManager].selectedTheme = indexPath.row;
  66. [self.tableView reloadData];
  67. [self displayUpdatedAlert];
  68. }
  69. }
  70. @end