RDSBaseTableViewController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // RDSBaseTableViewController.m
  3. // SmartLightForBigFish
  4. //
  5. // Created by coderYK on 2017/8/7.
  6. // Copyright © 2017年 RD-iOS. All rights reserved.
  7. //
  8. #import "RDSBaseTableViewController.h"
  9. #import "NSString+hanzi.h"
  10. @interface RDSBaseTableViewController ()
  11. @end
  12. @implementation RDSBaseTableViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. self.tableView.backgroundColor = RDSViewBgColor;
  16. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  17. //[self p_addRefreshHeader];
  18. }
  19. - (void)p_addRefreshHeader {
  20. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(rds_refresh)];
  21. header.automaticallyChangeAlpha = YES;
  22. header.lastUpdatedTimeLabel.hidden = YES;
  23. [header setTitle:@"" forState:MJRefreshStateIdle];
  24. [header setTitle:@"" forState:MJRefreshStatePulling];
  25. [header setTitle:@"" forState:MJRefreshStateRefreshing];
  26. [header setTitle:@"" forState:MJRefreshStateWillRefresh];
  27. self.tableView.mj_header = header;
  28. }
  29. - (void)rds_refresh {
  30. DDLog(@"请在子类中实现");
  31. }
  32. - (void)rds_showJuHuaOnWindow {
  33. if (self.juHua == nil) {
  34. UIActivityIndicatorView *juHua = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  35. self.juHua = juHua;
  36. self.juHua.hidesWhenStopped = YES;
  37. [[UIApplication sharedApplication].keyWindow addSubview:self.juHua];
  38. self.juHua.center = [UIApplication sharedApplication].keyWindow.center;
  39. }
  40. [self.juHua startAnimating];
  41. }
  42. - (void)rds_alertTitle:(NSString *)title message:(NSString *)message doneAction:(void(^)(void))doneActionBlock {
  43. UIAlertController *ac = [UIAlertController alertControllerWithTitle:title
  44. message:message
  45. preferredStyle:UIAlertControllerStyleAlert];
  46. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  47. if (doneActionBlock) {
  48. doneActionBlock();
  49. }
  50. }];
  51. [ac addAction:okAction]; // A
  52. [self presentViewController:ac animated:YES completion:nil];
  53. }
  54. - (void)rds_alertTitle:(NSString *)title message:(NSString *)message doneAction:(void (^)(void))doneActionBlock cancelAction:(void (^)(void))cancelActionBlock{
  55. UIAlertController *ac = [UIAlertController alertControllerWithTitle:title
  56. message:message
  57. preferredStyle:UIAlertControllerStyleAlert];
  58. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  59. if (doneActionBlock) {
  60. doneActionBlock();
  61. }
  62. }];
  63. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
  64. if (cancelActionBlock) {
  65. cancelActionBlock();
  66. }
  67. }];
  68. [ac addAction:okAction]; // A
  69. [ac addAction:cancelAction]; // B
  70. [self presentViewController:ac animated:YES completion:nil];
  71. }
  72. - (void)rds_alertInputTitle:(NSString *)title msg:(NSString *)msg placeholder:(NSString *)placeholder doneAction:(void(^)(NSString *name))doneActionBlock{
  73. UIAlertController *ac = [UIAlertController alertControllerWithTitle:title
  74. message:msg
  75. preferredStyle:UIAlertControllerStyleAlert];
  76. // 添加文本框
  77. [ac addTextFieldWithConfigurationHandler:^(UITextField * textField) {
  78. //textField.placeholder = placeholder;
  79. textField.text = placeholder;
  80. [textField addTarget:self action:@selector(p_alertInputDidChange:) forControlEvents:UIControlEventEditingChanged];
  81. }];
  82. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
  83. }];
  84. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  85. NSString *string = ac.textFields.firstObject.text;
  86. if (doneActionBlock) {
  87. doneActionBlock(string);
  88. }
  89. }];
  90. okAction.enabled = NO;
  91. [ac addAction:cancelAction];
  92. [ac addAction:okAction];
  93. [self presentViewController:ac animated:YES completion:nil];
  94. }
  95. - (void)p_alertInputDidChange:(UITextField *)sender{
  96. UIAlertController *ac = (UIAlertController *)self.presentedViewController;
  97. if (ac) {
  98. UIAlertAction *okAction = ac.actions.lastObject;
  99. NSString *string = ac.textFields.firstObject.text;
  100. NSUInteger length = [string rds_countStringByteLength];
  101. if (length >0 && length <= 16) {
  102. okAction.enabled = YES;
  103. ac.message = @"";
  104. }
  105. else if (length == 0){
  106. okAction.enabled = NO;
  107. ac.message = @"";
  108. }
  109. else if (length > 16){
  110. okAction.enabled = NO;
  111. ac.message = @"名称过长";
  112. }
  113. }
  114. }
  115. #pragma mark - Nav
  116. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
  117. if (self.navigationController != nil) {
  118. [self.navigationController pushViewController:viewController animated:animated];
  119. }
  120. else{
  121. [self.tabBarController.navigationController pushViewController:viewController animated:animated];
  122. }
  123. }
  124. - (UIViewController *)popViewControllerAnimated:(BOOL)animated{
  125. if (self.navigationController != nil) {
  126. return [self.navigationController popViewControllerAnimated:animated];
  127. }
  128. else{
  129. return [self.tabBarController.navigationController popViewControllerAnimated:animated];
  130. }
  131. }
  132. - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated{
  133. if (self.navigationController != nil) {
  134. return [self.navigationController popToViewController:viewController animated:animated];
  135. }
  136. else{
  137. return [self.tabBarController.navigationController popToViewController:viewController animated:animated];
  138. }
  139. }
  140. - (void)didReceiveMemoryWarning {
  141. [super didReceiveMemoryWarning];
  142. // Dispose of any resources that can be recreated.
  143. }
  144. @end