123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- //
- // RDSBaseTableViewController.m
- // SmartLightForBigFish
- //
- // Created by coderYK on 2017/8/7.
- // Copyright © 2017年 RD-iOS. All rights reserved.
- //
- #import "RDSBaseTableViewController.h"
- #import "NSString+hanzi.h"
- @interface RDSBaseTableViewController ()
- @end
- @implementation RDSBaseTableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.tableView.backgroundColor = RDSViewBgColor;
- self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- //[self p_addRefreshHeader];
- }
- - (void)p_addRefreshHeader {
-
- MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(rds_refresh)];
-
- header.automaticallyChangeAlpha = YES;
-
- header.lastUpdatedTimeLabel.hidden = YES;
-
- [header setTitle:@"" forState:MJRefreshStateIdle];
- [header setTitle:@"" forState:MJRefreshStatePulling];
- [header setTitle:@"" forState:MJRefreshStateRefreshing];
- [header setTitle:@"" forState:MJRefreshStateWillRefresh];
-
- self.tableView.mj_header = header;
- }
- - (void)rds_refresh {
-
- DDLog(@"请在子类中实现");
- }
- - (void)rds_showJuHuaOnWindow {
-
- if (self.juHua == nil) {
- UIActivityIndicatorView *juHua = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
- self.juHua = juHua;
- self.juHua.hidesWhenStopped = YES;
- [[UIApplication sharedApplication].keyWindow addSubview:self.juHua];
- self.juHua.center = [UIApplication sharedApplication].keyWindow.center;
- }
- [self.juHua startAnimating];
- }
- - (void)rds_alertTitle:(NSString *)title message:(NSString *)message doneAction:(void(^)(void))doneActionBlock {
-
- UIAlertController *ac = [UIAlertController alertControllerWithTitle:title
- message:message
- preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
-
- if (doneActionBlock) {
- doneActionBlock();
- }
- }];
- [ac addAction:okAction]; // A
-
- [self presentViewController:ac animated:YES completion:nil];
- }
- - (void)rds_alertTitle:(NSString *)title message:(NSString *)message doneAction:(void (^)(void))doneActionBlock cancelAction:(void (^)(void))cancelActionBlock{
-
- UIAlertController *ac = [UIAlertController alertControllerWithTitle:title
- message:message
- preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
-
- if (doneActionBlock) {
- doneActionBlock();
- }
- }];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
- if (cancelActionBlock) {
- cancelActionBlock();
- }
- }];
- [ac addAction:okAction]; // A
- [ac addAction:cancelAction]; // B
-
- [self presentViewController:ac animated:YES completion:nil];
- }
- - (void)rds_alertInputTitle:(NSString *)title msg:(NSString *)msg placeholder:(NSString *)placeholder doneAction:(void(^)(NSString *name))doneActionBlock{
-
- UIAlertController *ac = [UIAlertController alertControllerWithTitle:title
- message:msg
- preferredStyle:UIAlertControllerStyleAlert];
-
- // 添加文本框
- [ac addTextFieldWithConfigurationHandler:^(UITextField * textField) {
- //textField.placeholder = placeholder;
- textField.text = placeholder;
- [textField addTarget:self action:@selector(p_alertInputDidChange:) forControlEvents:UIControlEventEditingChanged];
- }];
-
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
- }];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
- NSString *string = ac.textFields.firstObject.text;
- if (doneActionBlock) {
- doneActionBlock(string);
- }
- }];
-
- okAction.enabled = NO;
- [ac addAction:cancelAction];
- [ac addAction:okAction];
-
-
- [self presentViewController:ac animated:YES completion:nil];
- }
- - (void)p_alertInputDidChange:(UITextField *)sender{
-
- UIAlertController *ac = (UIAlertController *)self.presentedViewController;
- if (ac) {
- UIAlertAction *okAction = ac.actions.lastObject;
- NSString *string = ac.textFields.firstObject.text;
- NSUInteger length = [string rds_countStringByteLength];
-
- if (length >0 && length <= 16) {
- okAction.enabled = YES;
- ac.message = @"";
- }
- else if (length == 0){
- okAction.enabled = NO;
- ac.message = @"";
- }
- else if (length > 16){
- okAction.enabled = NO;
- ac.message = @"名称过长";
- }
- }
- }
- #pragma mark - Nav
- - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
-
- if (self.navigationController != nil) {
- [self.navigationController pushViewController:viewController animated:animated];
- }
- else{
- [self.tabBarController.navigationController pushViewController:viewController animated:animated];
- }
- }
- - (UIViewController *)popViewControllerAnimated:(BOOL)animated{
-
- if (self.navigationController != nil) {
- return [self.navigationController popViewControllerAnimated:animated];
- }
- else{
- return [self.tabBarController.navigationController popViewControllerAnimated:animated];
- }
- }
- - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated{
-
- if (self.navigationController != nil) {
- return [self.navigationController popToViewController:viewController animated:animated];
- }
- else{
- return [self.tabBarController.navigationController popToViewController:viewController animated:animated];
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|