iOS

记录常用的公共方法,方便翻阅

2021-12-22  本文已影响0人  Kevin_wzx

目录

1.宏定义
2.弹框
3.枚举的定义
4.自定义页面按钮block回调
5.转菊花延时返回操作
6.自定义导航栏(原先的隐藏或者直接在基础上改)
7.找到当前的cell
8.接口传参数里面包含嵌套各种多层以及常见解析
9.用第三方 RZColorful 进行 UILabel富文本、UILabel 宽度自适应
10.tableview的代理和数据源的一套基本写法
11.数据处理:尽量在model和cell中去处理

1.宏定义

1.颜色
//RGB颜色设置
#define RGBCOLOR(r,g,b)     [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
//RGBA颜色设置-透明度
#define RGBACOLOR(r,g,b,a)  [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
// 十六进制颜色设置
#define HEXCOLOR(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
// 十六进制颜色设置-透明度
#define HEXACOLOR(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]
//随机颜色
#define KRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

//常用颜色
#define BBXBlue HEXCOLOR(0xFF3395FF)     //正常蓝色
#define BBXRed HEXCOLOR(0xFFF75A5A)      //正常红色
#define BBXGreen HEXCOLOR(0xFF57C871)    //正常绿色
#define BBXGray HEXCOLOR(0xFF666666)     //正常灰色-字体
#define BBXDarkGray HEXCOLOR(0xFFCCCCCC) //深灰色
#define BBXLightGray HEXCOLOR(0xFF999999)//浅灰色-字体
#define BBXBestLightGray HEXCOLOR(0xFFB3B3B3)//极浅灰色-字体(类似占位符颜色)
#define BBXBgGray HEXCOLOR(0xFFF4F4F4)   //背景浅灰色
#define BBXBlack HEXCOLOR(0xFF333333)    //正常黑色-字体
#define BBXWhite HEXCOLOR(0xFFFFFFFF)    //正常白色
#define BBXLineColor HEXCOLOR(0xEFEFF4)  //线条颜色
#define BBXHideViewColor HEXACOLOR(0x000000,0.2)//背景遮罩颜色
#define BBXOrangeColor HEXCOLOR(0xFF9601)  //正常橙色
#define PAGE_BG_COLOR HEXCOLOR(0xEFEFF4)   //用于背景底色和线条颜色

//其他颜色
#define kBlackColor          HEXCOLOR(0x1a1a1a)//全局黑色
#define kBlueColor           HEXCOLOR(0x282f48)//全局深蓝色
#define kLightBlueColor      HEXCOLOR(0x00aaff)//全局浅蓝色
#define kGrayTextColor       HEXCOLOR(0x898989)//灰色字体
#define kLineViewColor       HEXCOLOR(0xf0f0f0)//灰色线
#define kGrayBgColor         HEXCOLOR(0xf0f0f0)//灰色背景

2.尺寸|机型
2.1尺寸:
#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width //宽
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height //高

//iPhoneX / iPhoneXS
#define  isIphoneX_XS     (SCREEN_WIDTH == 375.f && SCREEN_HEIGHT == 812.f ? YES : NO)
//iPhoneXR / iPhoneXSMax
#define  isIphoneXR_XSMax    (SCREEN_WIDTH == 414.f && SCREEN_HEIGHT == 896.f ? YES : NO)
//异性全面屏
#define   isFullScreen    (isIphoneX_XS || isIphoneXR_XSMax)
// 状态栏高度
#define  statusBarHeight      (isFullScreen ? 44.f : 20.f)
//导航栏加状态栏高度(常说的导航栏高)
#define  statusBarAndNavigationBarHeight  (isFullScreen ? 88.f : 64.f)
//系统手势高度
#define system_gesture_height (isFullScreen ? 13 : 0)
//Tabbar高度
#define  tabbarHeight         (isFullScreen ? (49.f+34.f) : 49.f)
//Tabbar底部安全高度
#define  tabbarSafeBottomMargin         (isFullScreen ? 34.f : 0.f)
// Tabbar加底部安全高度(常说的Tabbar高)
#define Height_TabBar ((IS_IPHONE_X == YES || IS_IPHONE_Xr == YES || IS_IPHONE_Xs == YES || IS_IPHONE_Xs_Max == YES) ? 83.0 : 49.0)

2.2机型:
//判断是否是iPhone4s
#define IS_IPHONE4S (([[UIScreen mainScreen] bounds].size.height-480)?NO:YES)
//判断是否是iPhone5
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
//判断是否是iPhone6、iPhone7
#define IS_IPHONE6 (([[UIScreen mainScreen] bounds].size.height-667)?NO:YES)
//判断是否是iPhone6plush、7plus
#define IS_IPHONE6_PLUS (([[UIScreen mainScreen] bounds].size.height-736)?NO:YES)
// 判断iPhoneX
#define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !IsPad : NO)
// 判断iPHoneXr
#define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !IsPad : NO)
// 判断iPhoneXs
#define IS_IPHONE_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !IsPad : NO)
// 判断iPhoneXs Max
#define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !IsPad : NO)

//是否iPhone X 系列,用于判断是否有刘海
#define iPhoneX_Serious ([UIScreen mainScreen].bounds.size.height == 812 || [UIScreen mainScreen].bounds.size.height == 896)
//判断是否iPhone X 系列-用这个方法
#define kIsBangsScreen ({\
    BOOL isBangsScreen = NO; \
    if (@available(iOS 11.0, *)) { \
    UIWindow *window = [[UIApplication sharedApplication].windows firstObject]; \
    isBangsScreen = window.safeAreaInsets.bottom > 0; \
    } \
    isBangsScreen; \
})
// 判断是否是ipad
#define IsPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

2.3其他写法
// frame
#define kFrame(x,y,w,h)         CGRectMake((x), (y), (w), (h))
// UIEdgeInsets
#define kEdgeInsets(top,left,bottom,right) UIEdgeInsetsMake((top),(left),(left),(right))
// 创建点Point
#define  kPoint(x,y)             CGPointMake((x), (y))
// 创建尺寸size
#define  kSize(w,h)              CGSizeMake((w), (h))
// 由角度转换弧度
#define kDegreesToRadian(x)      (M_PI * (x) / 180.0)
// 由弧度转换角度
#define kRadianToDegrees(radian) (radian * 180.0) / (M_PI)

// 手机UI设计稿的宽高(kScreen_W就是屏幕宽,kScreen_H高)
#define kUI_W 375.0
#define kUI_H 667.0
// 适配比例 iPhone6 为标准  等比例缩放宽高位置 4(320*480) 5(320*568)6(375*667)6+(414*736)
#define kScale_W(w) ((w)*kScreen_W/kUI_W)
#define kScale_H(h) ((h)*(kScreen_H == 667 ? 667:736)/kUI_H)
#define kScale_Frame(x,y,w,h)  CGRectMake(((x)*kScreen_W/kUI_W), ((y)*kScreen_H/kUI_H), ((w)*kScreen_W/kUI_W), ((h)*kScreen_H/kUI_H))

//iPad系列
#define kPad_W 578.0
#define kPad_H 1024.0
#define kScalePad_W(w) ((w)*kPad_W/kUI_W)
#define kScalePad_H(h) ((h)*kPad_H/kUI_H)

3.字体(一些定义需要前提:项目中倒入ttf后缀的相关字体文件,如Roboto-Light.ttf,上网下载)
// 字体
#define kFont_Medium(x) [UIFont fontWithName:@"HelveticaNeue-Medium" size:x]
#define kFont_Bold(x) [UIFont systemFontOfSize:x weight:UIFontWeightBold]
#define kFont_Regular(x) [UIFont fontWithName:@".HelveticaNeueInterface-Regular" size:x]
#define kFont_Heavy(x) [UIFont fontWithName:@".HelveticaNeueInterface-Heavy" size:x]
#define kFont_Light(x) [UIFont fontWithName:@"PingFang-SC-Light" size:x]
#define kFont_PingFang(x) [UIFont fontWithName:@"PingFang-SC" size:x]
// 适配字体大小
#define kScale_Font(x) [UIFont systemFontOfSize:(x*kScreen_W/kUI_W)]
// 适配值
#define kScale_Num(x) (x*kScreen_W/kUI_W)
// 字体大小
#define kFont(x) [UIFont systemFontOfSize:x]

4.判空
//判断是否空字符串
#define isNullString(s) (!s || ![s isKindOfClass:NSString.class] || [(NSString *)s isEqualToString:@""])
//判断是否是空数组
#define isNullArray(s) (!s || ![s isKindOfClass:NSArray.class] || [(NSArray *)s count] == 0)
//判断是否是空字典
#define kIsEmptyDic(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0 || dic.count == 0)
//判断是否是空对象
#define kIsEmptyObj(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

5.打印输出
定义方法一:
#define BUD_Log(frmt, ...)   \
do {                                                      \
NSLog(@"【BUAdDemo】%@", [NSString stringWithFormat:frmt,##__VA_ARGS__]);  \
} while(0)

#define DLog(...) printf("%s [Line %d] %s\n\n", __PRETTY_FUNCTION__, __LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String])

定义方法二:
#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif

#ifdef DEBUG
#define SXLog(...) NSLog(__VA_ARGS__)
#else
#define SXLog(...) do { } while (0)
#endif

其他:
//消除 warning
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

6.缩写
6.1常规缩写
//国际化宏
#define NSLocalizedStringEx(key, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:LocalizdFileName]
//国际化语言
#define kLocLanguage(str) [[[XXAppManager Shared] currentLanguageBundle] localizedStringForKey:str value:@"" table:nil]
//弱引用weakSelf
#define WeakSelf __weak typeof(self)weakSelf = self;
//strongSelf
#define StrongSelf __strong __typeof(weakSelf)strongSelf = weakSelf;
// 获取Window
#define kWindow [UIApplication sharedApplication].keyWindow
// AppDelegate对象
#define kAppDelegate [[UIApplication sharedApplication] delegate]
// Application
#define kApplication        [UIApplication sharedApplication]
// UserDefaults
#define kUserDefaults       [NSUserDefaults standardUserDefaults]
#define kUserDefaultObject(key)      [[NSUserDefaults standardUserDefaults] objectForKey:key]
// 获取图片资源
#define kImage(imgName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imgName]]
// 打开网络地址
#define kOpenUrl(url) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
// IndexPath
#define kIndexPath(x,y) [NSIndexPath indexPathForRow:(y) inSection:(x)]
// IndexSet
#define kIndexSet(x) [NSIndexSet indexSetWithIndex:(x)]
// App Store 地址(替换APPID)
#define kAppDLUrl @"itms-apps://itunes.apple.com/app/id1026687540"
// App版本号
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
// 手机系统版本
#define KSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
// 获取当前语言
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

6.2判断系统
// 判断iOS7 或者7 之后
#define IOS7_OR_LATER   ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
//判断是否是iOS8及以上
#define IOS8_OR_LATER   ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
//判断是否是iOS9及以上
#define IOS9_OR_LATER   ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
#define IOS8 ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0 && [[UIDevice currentDevice].systemVersion doubleValue] < 9.0)
#define IOS8_10 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 && [[UIDevice currentDevice].systemVersion doubleValue] < 10.0)
#define IOS10 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0)
#define LessIOS11 ([[[UIDevice currentDevice] systemVersion] floatValue] <= 11.0)

6.3其他
//通知中心
#define  kNotificationCenter [NSNotificationCenter defaultCenter]
//时间(单位这里为秒)
#define timeInterval 5 //5秒
//设置按钮高度
#define BUTTONHEIGHT (kIsBangsScreen?(BUTTON_Height+34):(BUTTON_Height+18))
//字符串空处理
#define kNSStringWithString(str)    [NSString stringWithString:(str?str:@"")]

7.关于数据的一些常规判断
#define kIntValue(str) [kIsEmptyStrReplac(str,@"0")  intValue]
#define kFloatValue(str) [kIsEmptyStrReplac(str,@"0.0") floatValue]
//字符串转化
#define kString(str)  [NSString stringWithFormat:@"%@",str]
#define kStrNum(num)  [NSString stringWithFormat:@"%@",@(num)]
#define kStrUrl(str) [NSString stringWithFormat:@"http://%@",str]
#define kStrMerge(str1,str2)  [NSString stringWithFormat:@"%@%@",str1,str2]
#define kUrl(str1)  [NSURL URLWithString:[NSString stringWithFormat:@"%@",str1]]
#define kRequest(str1) [NSURLRequest requestWithURL:[NSURL URLWithString:str1]]
//判断字符串是否相同
#define kStrEqual(str1,str2) [[NSString stringWithFormat:@"%@",str1] isEqualToString:[NSString stringWithFormat:@"%@",str2]]

字体相关文件链接: https://pan.baidu.com/s/1b5NrR7Y97gzfRTRX5tSlLw 提取码: tja7

2.弹框

UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"定位权限请选择“始终”,否则服务无法使用!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  [self.navigationController popToRootViewControllerAnimated:YES];
}];
UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"前往开启" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

typedef enum BBXWalletAlertViewType {
    
    BBXWalletAlertViewType_OneButton = 0,//一个按钮
    BBXWalletAlertViewType_TwoButton,//两个按钮
    BBXWalletAlertViewType_Title//一个按钮+有标题无标题图片
} BBXWalletAlertViewType;

typedef void (^leftBtnBlock)();
typedef void (^rightBtnBlock)();
typedef void (^sureBtnBlock)();

@interface BBXWalletAlertView : UIView

@property (nonatomic ,strong) UIView *contentBgView;
@property (nonatomic ,strong) UIImageView *statusImage;
@property (nonatomic ,strong) UILabel *titleLB;
@property (nonatomic ,strong) UILabel *contentLabel;
@property (nonatomic ,strong) UIButton *leftBtn;
@property (nonatomic ,strong) UIButton *rightBtn;
@property (nonatomic ,strong) UIButton *sureBtn;
@property (nonatomic , copy) leftBtnBlock leftBlock;
@property (nonatomic , copy) rightBtnBlock rightBlock;
@property (nonatomic , copy) sureBtnBlock sureBlock;
@property (nonatomic ,strong) UIView *verticalLine;
@property (nonatomic, assign) BBXWalletAlertViewType walletAlertViewType;

- (void)initShowWithAlertType:(BBXWalletAlertViewType)type topImage:(UIImage *)topImage titleStr:(NSString *)titleStr contentStr:(NSString *)contentStr leftBtnName:(NSString *)leftBtnName rightBtnName:(NSString *)rightBtnName sureBtnName:(NSString *)sureBtnName;

@end
#import "BBXWalletAlertView.h"

@implementation BBXWalletAlertView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = RGBACOLOR(0, 0, 0, 0.4);
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    
    [self addSubview:self.contentBgView];
    [self.contentBgView addSubview:self.contentLabel];
    [self.contentBgView addSubview:self.statusImage];
    [self.contentBgView addSubview:self.sureBtn];
    [self.contentBgView addSubview:self.leftBtn];
    [self.contentBgView addSubview:self.rightBtn];
}

- (void)initShowWithAlertType:(BBXWalletAlertViewType)type topImage:(UIImage *)topImage titleStr:(NSString *)titleStr contentStr:(NSString *)contentStr leftBtnName:(NSString *)leftBtnName rightBtnName:(NSString *)rightBtnName sureBtnName:(NSString *)sureBtnName {
    _walletAlertViewType = type;
    self.titleLB.text = titleStr;
    self.statusImage.image = topImage;
    self.contentLabel.text = contentStr;
    [self.leftBtn setTitle:leftBtnName forState:0];
    [self.rightBtn setTitle:rightBtnName forState:0];
    [self.sureBtn setTitle:sureBtnName forState:0];
    [self setWalletAlertViewType:type];
}

- (void)setWalletAlertViewType:(BBXWalletAlertViewType)walletAlertViewType {
    
    _walletAlertViewType = walletAlertViewType;
    if (_walletAlertViewType == BBXWalletAlertViewType_OneButton) {
        [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentBgView);
            make.centerY.mas_equalTo(self.contentBgView);
            make.height.mas_equalTo(40);
            make.left.mas_equalTo(20);
    
        }];
        self.sureBtn.hidden = NO;
        self.leftBtn.hidden = YES;
        self.rightBtn.hidden = YES;
        self.verticalLine.hidden = YES;
        self.titleLB.hidden = YES;
        self.statusImage.hidden = NO;
    } else if (_walletAlertViewType == BBXWalletAlertViewType_TwoButton) {
        
        self.sureBtn.hidden = YES;
        self.leftBtn.hidden = NO;
        self.rightBtn.hidden = NO;
        self.verticalLine.hidden = NO;
        self.titleLB.hidden = YES;
        self.statusImage.hidden = NO;
    } else if (_walletAlertViewType == BBXWalletAlertViewType_Title) {

        [self.contentBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(52.5);
            make.height.mas_equalTo(216);
        }];
        [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentBgView);
            make.centerY.mas_equalTo(self.contentBgView);
            make.bottom.mas_equalTo(-44);
            make.left.mas_equalTo(20);
        }];
        self.sureBtn.hidden = NO;
        self.leftBtn.hidden = YES;
        self.rightBtn.hidden = YES;
        self.verticalLine.hidden = YES;
        self.titleLB.hidden = NO;
        self.statusImage.hidden = YES;
    }
}

#pragma mark -- lazyinit
- (UIView *)contentBgView {
    
    if (!_contentBgView) {
        _contentBgView = [[UIView alloc]init];
        [self addSubview:_contentBgView];
        _contentBgView.backgroundColor = [UIColor whiteColor];
        _contentBgView.layer.cornerRadius = 12;
        _contentBgView.layer.masksToBounds = YES;
        [_contentBgView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.centerX.mas_equalTo(self);
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(52.5);
            make.height.mas_equalTo(156);
        }];
        
        _verticalLine = [[UIView alloc]init];
        [_contentBgView addSubview:_verticalLine];
        _verticalLine.layer.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0].CGColor;
        [_verticalLine mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.centerX.mas_equalTo(_contentBgView);
            make.height.mas_equalTo(44);
            make.bottom.mas_equalTo(0);
            make.width.mas_equalTo(0.5);
        }];
        
        UIView *leftLine = [[UIView alloc]init];
        [_contentBgView addSubview:leftLine];
        leftLine.layer.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0].CGColor;
        [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.right.mas_equalTo(0);
            make.height.mas_equalTo(0.5);
            make.bottom.mas_equalTo(-43.5);
            make.left.mas_equalTo(0);
        }];
    }
    return _contentBgView;
}

- (UIImageView *)statusImage {
    if (!_statusImage) {
        _statusImage = [[UIImageView alloc]init];
        [self.contentBgView addSubview:_statusImage];
        [_statusImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentLabel);
            make.width.height.mas_equalTo(22);
            make.bottom.mas_equalTo(self.contentLabel.mas_top).offset(-15);
        }];
    }
    return _statusImage;
}

- (UILabel *)titleLB {
    if (!_titleLB) {
        _titleLB = [[UILabel alloc]init];
        [self.contentBgView addSubview:_titleLB];
        _titleLB.backgroundColor = [UIColor clearColor];
        _titleLB.textColor = BBXBlack;
        _titleLB.font = [UIFont systemFontOfSize:16];
        _titleLB.textAlignment = NSTextAlignmentCenter;
        [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentBgView);
            make.bottom.mas_equalTo(self.contentLabel.mas_top).offset(-5);
            make.height.mas_equalTo(20);
            make.left.mas_equalTo(20);
        }];
    }
    return _titleLB;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc]init];
        [self.contentBgView addSubview:_contentLabel];
        _contentLabel.backgroundColor = [UIColor clearColor];
        _contentLabel.textColor = BBXBlack;
        _contentLabel.font = [UIFont systemFontOfSize:15];
        _contentLabel.textAlignment = NSTextAlignmentCenter;
        _contentLabel.numberOfLines = 0;
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentBgView);
            make.centerY.mas_equalTo(self.contentBgView);
            make.height.mas_equalTo(20);
            make.left.mas_equalTo(20);
        }];
    }
    return _contentLabel;
}

- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentBgView addSubview:_leftBtn];
        [_leftBtn setTitleColor:BBXBlack forState:0];
        _leftBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        [_leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.bottom.mas_equalTo(self.contentBgView.mas_bottom).offset(0);//-9.5
            make.height.mas_equalTo(44);
            make.left.mas_equalTo(self.contentBgView.mas_left).offset(10);
            make.right.mas_equalTo(self.contentBgView.mas_centerX).offset(-10);
        }];
    }
    return _leftBtn;
}

- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentBgView addSubview:_rightBtn];
        [_rightBtn setTitleColor:BBXBlue forState:0];
        _rightBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        [_rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _rightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.centerY.mas_equalTo(self.leftBtn);
            make.height.mas_equalTo(self.leftBtn);
            make.left.mas_equalTo(self.contentBgView.mas_centerX).offset(10);
            make.right.mas_equalTo(self.contentBgView.mas_right).offset(-10);
        }];
    }
    return _rightBtn;
}

- (UIButton *)sureBtn {
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentBgView addSubview:_sureBtn];
        [_sureBtn setTitleColor:BBXBlue forState:0];
        _sureBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        [_sureBtn addTarget:self action:@selector(sureBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _sureBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.contentBgView.mas_bottom).offset(0);//-9.5
            make.height.mas_equalTo(self.leftBtn);
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
        }];
    }
    return _sureBtn;
}

#pragma mark -- action
- (void)showView {
    [kWindow addSubview:self];
}

- (void)hideView {
    [self removeFromSuperview];
}

- (void)leftBtnClick {
    if (self.leftBlock) {
        self.leftBlock();
    }
    [self hideView];
}

- (void)rightBtnClick {
    if (self.rightBlock) {
        self.rightBlock();
    }
    [self hideView];
}

- (void)sureBtnClick {
    if (self.sureBlock) {
        self.sureBlock();
    }
    [self hideView];
}
@property (nonatomic, strong) BBXWalletAlertView *cancelOrderAlertView;//取消订单

//取消订单
- (void)cancelOrderAction:(UITapGestureRecognizer *)tap {
    WeakSelf
    self.cancelOrderAlertView = [[BBXWalletAlertView alloc]init];
    [self.view.window addSubview:self.cancelOrderAlertView];
    [self.cancelOrderAlertView.leftBtn setTitleColor:BBXBlue forState:0];
    [self.cancelOrderAlertView.rightBtn setTitleColor:BBXBlack forState:0];
    [self.cancelOrderAlertView initShowWithAlertType:BBXWalletAlertViewType_TwoButton topImage:kImage(@"scan_icon_notice") titleStr:@"" contentStr:@"是否确定取消订单?一天只允许取消2次!" leftBtnName:@"确定取消" rightBtnName:@"我再想想" sureBtnName:@""];
    [self.cancelOrderAlertView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.mas_equalTo(0);
    }];
    [self.cancelOrderAlertView.contentBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.cancelOrderAlertView);
        make.centerY.mas_equalTo(self.cancelOrderAlertView);
        make.left.mas_equalTo(52.5);
        make.height.mas_equalTo(160);
    }];
    [self.cancelOrderAlertView.statusImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.cancelOrderAlertView.contentLabel);
        make.width.height.mas_equalTo(22);
        make.bottom.mas_equalTo(self.cancelOrderAlertView.contentLabel.mas_top).offset(0);
    }];
    [self.cancelOrderAlertView.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.cancelOrderAlertView.contentBgView);
        make.centerY.mas_equalTo(self.cancelOrderAlertView.contentBgView);
        make.bottom.mas_equalTo(-44);
        make.left.mas_equalTo(20);
    }];
    self.cancelOrderAlertView.leftBlock = ^{
        [weakSelf loadCancelOrder];
    };
}

3.枚举的定义

typedef enum CHCouponBlueAlertViewState {//枚举名 _ 类型
    CHCouponBlueAlertViewState_noConnect = 0,
    CHCouponBlueAlertViewState_connecting,
    CHCouponBlueAlertViewState_connectSuc,
    CHCouponBlueAlertViewState_connectFail,
} CHCouponBlueAlertViewState;
typedef NS_ENUM(NSUInteger, CHMyOrderControllerFromType) {
    CHMyOrderControllerFromType_Default, //不需要操作
    CHMyOrderControllerFromType_UserCenter, // 用户中心
    CHMyOrderControllerFromType_ConfirmOrder // 确认订单
};

例如:

定义枚举 重写set方法

4.自定义页面按钮block回调

定义block 设置代码
typedef void(^XXObjBlock)(id obj);
typedef void(^XXDictionaryBlock)(NSDictionary *dic);
typedef void(^XXArrayBlock)(NSArray *arr);
typedef void(^XXBOOLBlock)(BOOL isTrue);
typedef void(^XXIntegerBlock)(NSInteger num);
typedef void(^XXFloatBlock)(CGFloat num);
typedef void(^XXVoidBlock)(void);
typedef void(^XXCallBackBlock)(NSString *str,NSInteger num);
typedef void(^numberBlock)(NSNumber *result);
typedef void(^stringBlock)(NSString *result);
typedef void(^stringBlock2)(NSString *result,NSString *description);
typedef void(^arrayAndDescription)(NSArray *results,NSString *description);

5.转菊花延时返回操作

[MBProgressHUD showMessag:kLocLanguage(@"txt_ZXActivateCodeDetailViewController_activeSuccess") toView:self.view andShowTime:1.5];
   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
     [self backBtnClicked];
});
#define FIVE_SECOND 5

@property (nonatomic, strong) NSTimer *dataTimer;//5秒刷新一次数据的定时器

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self startOrderFresh];//1分钟刷新一次数据的定时器
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [_dataTimer invalidate];
}

//更新数据,保持订单新鲜
- (void)startOrderFresh {
    if (!_dataTimer) {
        _dataTimer = [NSTimer scheduledTimerWithTimeInterval:One_MINUTE_SECOND target:self selector:@selector(refreshEvent) userInfo:nil repeats:YES];
    }
}

- (void)refreshEvent {
    [self refreshEventWithLat:self.refreshLat Lng:self.refreshLng];
}

6.自定义导航栏(原先的隐藏或者直接在基础上改)

- (UIView *)navView {
    if (!_navView)
    {
        _navView = [[UIView alloc] initWithFrame:kFrame(0, 0, kScreen_W, kNav_H)];
        _navView.backgroundColor = kColor_White;
    
        UIButton *closeBtn = [[UIButton alloc] xx_initWithFrame:kFrame(15, 32+kSafeAreaBottomHeight,  25, 25) img:@"icon_close" bgImg:nil cornerRadius:0 Block:^(NSInteger tag) {
            [self xx_pop];
        }];
    
        [_navView addSubview:closeBtn];
    }
    return _navView;
}

7.找到当前的cell

NSIndexPath *index = [NSIndexPath indexPathForRow:self.dataArr.count-1 inSection:0];

// 刷新当前cell
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

8.接口传参数里面包含嵌套各种多层以及常见解析

一、接口上传参数(包含字典、数组、单个字符串/int类型等)

接口传参数的时候需要注意:
1.参数判断空处理
2.参数类型是否与后台定义的匹配对应,比如数组、字典、NSNumber、字符串、int等类型
3.接口是否需要加密,解析数据可能需要解密

//上传参数方法
- (void)upParameter {
    int basePrice = self.orderDetailModel.price?[self.orderDetailModel.price intValue]:self.orderItem.priceFen;
    NSString *dateStr = self.orderDetailModel.appoint_time?self.orderDetailModel.appoint_time:(self.orderItem.itemAppointmentTime?:@"");
    NSDictionary *priceDetailDic = @{@"base_price": @(basePrice)};//班次选的那张票的原价
    NSDictionary *commonParams = @{
                                  @"access_token":[SKUserInfo shareManager].userToken?[SKUserInfo shareManager].userToken:@"",
                                  @"uid":[SKUserInfo shareManager].userID?[SKUserInfo shareManager].userID:@"",
                                  @"appoint_type":@(0),
                                  @"appoint_time":dateStr,
                                  @"car_class_id":@"allcarclass",
                                  @"line_id":self.orderItem.itemLineID?self.orderItem.itemLineID:@"",
                                  @"city":self.orderItem.itemCity?self.orderItem.itemCity:@"",
                                  @"order_type":@(OrderType_Bus),
                                  @"price_detail":priceDetailDic,//字典
                                  @"order_origin":@(OrderOrigin_Type_APP),
                                  @"time":[[NSDate date] description],
                                  };
    NSMutableDictionary * dataDic =  [NSMutableDictionary dictionaryWithDictionary:commonParams];
    NSString *url = [BBXURL domainAppendString:@"/api/price/get_usable_sale_list"];
    [[NetworkClient sharedInstance] cj_postUrl:url params:dataDic encrypt:YES completeBlock:^(NSDictionary * _Nonnull responseObject) {
      //数据处理内容省略......
    }
}
//上传参数方法(有数组/字典)
- (void)upParameter {
    
    //detialDic字典参数(直接设置写法)
    NSMutableDictionary *detialDic = [@{@"sale_id":@(0),@"sale_type":@(0),@"sale_amount":@(0)} mutableCopy];
    //couponDic字典参数(setObject写法)
    NSMutableDictionary *couponDic = [[NSMutableDictionary alloc] init];
    [couponDic setObject:detialDic forKey:@"price_detail"];
    [detialDic setObject:self.saleMsgDic[@"saleDic"][@"sale_type"] forKey:@"sale_type"];
    [couponDic setObject:@(self.orderItem.couponModel.couponId?self.orderItem.couponModel.couponId:0) forKey:@"coupon_id"];
    //最终组装需要的couponsArray数组参数
    NSMutableArray *couponsArray = [[NSMutableArray alloc] init];
    [couponsArray addObject:couponDic];
    
    //orderArray数组参数
    NSMutableArray *orderArray = [[NSMutableArray alloc] init];
    NSDictionary *orderDic = @{@"orderType":@(OrderType_Bus),@"app_type":@(OrderOrigin_Type_APP),@"flights_id":@(-508),@"order_id":self.orderDetailModel.order_id,@"other_fee":@(0)};
    [orderArray addObject:orderDic];
    
    //大参数组装
    NSMutableDictionary *payOrderDic = [@{
                                  @"access_token":[SKUserInfo shareManager].userToken?[SKUserInfo shareManager].userToken:@"",
                                  @"uid":[SKUserInfo shareManager].userID?[SKUserInfo shareManager].userID:@"",
                                  @"coupon_id":self.orderDetailModel.coupon_id?:@(0),
                                  @"coupons":couponsArray,//数组
                                  @"open_id":[[SKUserInfo shareManager] userOpenID],
                                  @"orders":orderArray,//数组
                                  @"order_id":self.orderDetailModel.order_id,
                                  @"order_type":@(OrderType_Bus),
                                  @"app_type":@(OrderOrigin_Type_APP),
                                  @"flights_id":@(-508),
                                  @"other_fee":@(0),
                                  @"gateway":item.itemIdentify,
                                  } mutableCopy];
    NSString *url = [BBXURL domainAppendString:@"/api/pay/external_prepay"];
    [[NetworkClient sharedInstance] cj_postUrl:url params:payDic encrypt:YES completeBlock:^(NSDictionary * _Nonnull responseObject) {
        //数据处理内容省略......
    }
}

二、解析数据(包含字典、数组、单个字符串/int类型等)

1.对于后台返回的字典值responseObject判断不为空
2.数组和非字符串解析和赋值判断不为空
3.在网络请求里面解析数据之后需要对UI刷新的记得加主线程刷新,否则容易奔溃
MJ官方解析方法说明:https://github.com/CoderMJLee/MJExtension

@property (nonatomic, assign) NSNumber *rebookedOrderStatus;
@property (nonatomic, copy) NSString *refundFeeStr;//退款手续费
@property (nonatomic, copy) NSString *refundPerStr;//退款
@property (nonatomic, assign) double zhongxinYuerStr;//中信余额

//解析数据方法
- (void)JiexiShuju {
    
    [[NetworkClient sharedInstance] cj_postUrl:url params:dataDic encrypt:YES completeBlock:^(NSDictionary * _Nonnull responseObject) {
        NSString *message = responseObject[@"message"];
        if ([responseObject isKindOfClass:[NSDictionary class]] && responseObject != nil) {//首先确保返回的有值,否则返回为空就奔溃
            if ([responseObject[@"status"]integerValue] == 0) {//请求成功
                NSDictionary *result = responseObject[@"result"];
                //解析字符串
                NSString *refundFee = result[@"fee"];
                NSString *refundPer = result[@"per"];
                self.refundFeeStr = refundFee;
                self.refundPerStr = refundPer;

                //解析double
                double citicBalance = [responseObject[@"citicBalance"] floatValue];//中信账户余额
                self.zhongxinYuerStr = citicBalance;

                //解析NSNumber
                if (result[@"order_status"]) {
                    self.rebookedOrderStatus = [NSNumber numberWithInt:[result[@"order_status"] intValue]];
                    self.rebookOrderID = result[@"order_id"];
                }
            } else {
                [SKToast showWithText:message];
            }
        } else {
            [SKToast showWithText:@"返回为空,错误"];
        }
    }];
}
@property (nonatomic, strong) NSMutableArray *dataArray;
- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}

//解析数据方法
- (void)JiexiShuju {
    __weak __typeof(self)weakSelf = self;
    [SVProgressHUD show];
    [[NetworkClient sharedInstance] cj_agentPostDomainName:url domainParams:params encrypt:YES completeBlock:^(NSDictionary *responseObject) {
        [SVProgressHUD dismiss];
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        NSString *status = responseObject[@"status"];
        NSString *message = responseObject[@"message"];
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            if ([responseObject[@"status"] intValue] == 0) {
                NSArray *dataA = [responseObject[@"data"] copy];
                self.dataArray = [BBXPayRecordListModel mj_objectArrayWithKeyValuesArray:dataA];
                [self.tableView reloadData];
            } else {
                [strongSelf.view showRequestFailToast:message];
            }
        } else {
            [SKToast showWithText:message];//@"网络错误"
        }
    }];
}
数组赋值
//解析数据方法
- (void)JiexiShuju {
    __weak __typeof(self)weakSelf = self;
    [[NetworkClient sharedInstance] cj_postUrl:url params:params encrypt:YES completeBlock:^(NSDictionary *responseObject) {
        [SVProgressHUD dismiss];
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            if ([responseObject[@"status"] intValue] == 0) {
                //字典解析
                BBXDataReporteCalendarModel *calendarModel = [BBXDataReporteCalendarModel modelWithDictionary:responseObject[@"result"][@"result"]];
                strongSelf.calendarModel = calendarModel;
                NSDictionary *calendarDic = responseObject[@"result"][@"result"][@"calendarDatas"];
                //更新UI
                dispatch_async(dispatch_get_main_queue(), ^{
                    if (kStrEqual(calendarModel.uploadStatus, @"0")) {//未上报(缺)- 包含今日
                        weakSelf.navRightBar.hidden = NO;
                        weakSelf.dataReportBtn.hidden = NO;
                        [weakSelf.dataReportBtn setTitle:@"开始上报" forState:0];
                    } else if (kStrEqual(calendarModel.uploadStatus, @"1")) {//1:已提交(已上报) - 包含今日
                        weakSelf.dataReportBtn.hidden = NO;
                        [weakSelf.dataReportBtn setTitle:@"修改" forState:0];
                    } else {
                        
                    }
                    [weakSelf.tableView reloadData];
                });
            } else {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [SKToast showWithText:@"网络错误"];
                });
            }
        } else {
            dispatch_async(dispatch_get_main_queue(), ^{
                [SKToast showWithText:@"网络错误"];
            });
        }
    }];
}

返回的嵌套数据结构

{
    message = success;
    result =     {
        "menu_config" =         {
            "current_menu" = "1_3";
            menu =             (
                                {
                    id = 1;
                    name = "\U8de8\U57ce";
                    "sub_menu" =                     (
                                                {
                            id = "1_3";
                            name = "\U63a5\U9001\U673a";
                            tag = "";
                        }
                    );
                    tag = dd;
                },
                                {
                    id = 4;
                    name = "\U987a\U98ce\U8f66";
                    "sub_menu" =                     (
                    );
                    tag = "";
                }
            );
        };
    };
    status = 0;
}
返回的嵌套数据结构

解析数据的代码

//跨城-底部策略后台配置子任务
- (void)requestSubtaskConfigData {
    if (isNullString(self.locationModel.province) || isNullString(self.locationModel.city) || isNullString(self.locationModel.district)) {
        return;
    }
    NSString *url = [BBXURL domainAppendString:@"/api/line/get_app_config_v3"];
    NSDictionary *params = @{@"uid":[SKUserInfo shareManager].userID,
                             @"access_token":[SKUserInfo shareManager].userToken,
                             @"province":self.normalStartAddress.province,
                             @"city":self.normalStartAddress.city,
                             @"area":self.normalStartAddress.district,
                             @"cur_location":@{@"lat":@(self.normalStartAddress.coordinate.latitude),
                                               @"lng":@(self.normalStartAddress.coordinate.longitude)},
    };
    __weak __typeof(self)weakSelf = self;
    [[NetworkClient sharedInstance] cj_postUrl:url params:params encrypt:YES completeBlock:^(NSDictionary * _Nonnull responseObject) {
        [SVProgressHUD dismiss];
        
        if (!responseObject[@"status"] || [responseObject[@"status"] integerValue] != 0) {
            //坑爹接口有时候会返回失败,此时要多请求几次
            static NSInteger tryTimes = 0;
            if (tryTimes <= 3) {
                [self requestSubtaskConfigData];
                tryTimes++;
            }
            return;
        }
        
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        //菜单:跨城id为1;子菜单:定制快线1_1、跨城速递1_2、接送机1_3、一键叫车1_4;市内id为2,代驾3,顺风车4,汽车票5
        BBXConfigSubMenuModel *configSunMenuModel = [BBXConfigSubMenuModel modelWithJSON:responseObject[@"result"]];
        strongSelf.configSubMenuModel = configSunMenuModel;
        NSArray *dataAarry = [configSunMenuModel.menu_config.menu copy];
        NSMutableArray *kuachengArry = [[NSMutableArray alloc]init];
        if (dataAarry.count>0) {
            for (NSDictionary *dic in dataAarry) {
                if (kStrEqual(dic[@"id"], @"1")) {//1:跨城
                    [kuachengArry addObject:dic];
                }
            }
            
            NSArray *menuArray = [[NSArray alloc]init];
            NSArray *subMenuArray = [[NSArray alloc]init];
            NSMutableArray *arr = [[NSMutableArray alloc]init];
            menuArray = [Menu mj_objectArrayWithKeyValuesArray:kuachengArry];
            for (Menu *model in menuArray) {
                subMenuArray = model.sub_menu;
            }
            
            for (Sub_menu *model in subMenuArray) {
                [arr addObject:model];
            }
            
            if (subMenuArray.count>1 && subMenuArray.count<4) {//本地创造返回类型的结构数据加入到数组
                Sub_menu *model = [[Sub_menu alloc]init];
                model.id = @"999999";
                model.name = @"敬请期待";
                model.tag = @"";
                [arr addObject:model];
            }
            self.menuDataArray = [Sub_menu mj_objectArrayWithKeyValuesArray:arr];//字典数组转模型数组
            if (self.menuDataArray.count>4) {
                self.menuCollectionView.scrollEnabled = YES;
            }
            [self.menuCollectionView reloadData];
        }
    }];
}

断点的关键数据查看

//网络请求,刷新界面
- (void)refreshEventWithLat:(NSString *)lat Lng:(NSString *)lng {
    
    NSDictionary *params = @{
                             @"line_id":[BBXDriverInfo shareManager].line_id?:@"",
                             @"max_distance":@(1000),//1公里范围内
                             @"min_distance":@(0),
                             @"location":@{@"lat":lat?:@"",
                                           @"lng":lng?:@""
                                          }
                             };
    [SVProgressHUD show];
    @weakify(self);
    [BBXAPIHTTP yh_requestBBXWithParameter:params adnFinishBlock:^(RequestResultObj *resultObj) {
        @strongify(self);
        [SVProgressHUD dismiss];
        if([resultObj.data isKindOfClass:[NSDictionary class]]) {
            
            NSInteger status = [resultObj.data[@"status"] integerValue];
            NSString * message = resultObj.data[@"message"];
            if(status == 200) {//成功
                [self.orderArray removeAllObjects];//移除所有数据
                [self.mapView removeAnnotations:self.mapView.annotations];//移除地图上的所有标注
                NSArray *dataA = [resultObj.data[@"result"] copy];
                self.orderArray = [BBXRepDriveDistributeModel mj_objectArrayWithKeyValuesArray:dataA];
                
                //重新排序
                NSMutableArray *kongArr = [[NSMutableArray alloc] init];//空闲
                NSMutableArray *noKongArr = [[NSMutableArray alloc] init];//非空闲
                for (BBXRepDriveDistributeModel *disModel in self.orderArray) {
                    if (kStrEqual(disModel.show_status, @"0")) {//0:空闲
                        [kongArr addObject:disModel];
                    } else {
                        [noKongArr addObject:disModel];
                    }
                }
                NSArray *kong = [NSArray arrayWithArray:kongArr];//空闲
                NSArray *noKong = [NSArray arrayWithArray:noKongArr];//非空闲
                noKong = [noKong arrayByAddingObjectsFromArray:kong];//kong排在noKong后面,后加入描点在最上面
                self.orderArray = [NSMutableArray arrayWithArray:noKong];
                
                
                for (NSDictionary *dict in self.orderArray) {
                    NSDictionary *poiDict = dict;
                    BBXRepDriveDistributeModel *poi = [BBXRepDriveDistributeModel mj_objectWithKeyValues:poiDict];
                    BBXRepDrivePointAnnotation *annotation = [[BBXRepDrivePointAnnotation alloc] init];
                    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([poi.location.lat doubleValue], [poi.location.lng doubleValue]);
                    annotation.coordinate = coordinate;
                    annotation.distributrModel = poi;
                    [self.mapView addAnnotation:annotation];
                }
            } else {
                [SVProgressHUD dismiss];
                [self.view showRequestFailToast:message];
            }
        } else{
            [SVProgressHUD dismiss];
            [self.view showRequestFailToast:nil];
        }
    } andRequestURl:[BBXURL getReplaceAllDriveDistribution] toCrypt:YES];
}

9.用第三方 RZColorful 进行 UILabel富文本、UILabel 宽度自适应

pod:
pod 'RZColorful'

赋值:
[self.ruleLabel rz_colorfulConfer:^(RZColorfulConferrer * _Nonnull confer) {
  confer.text(@"提现规则:\n").textColor([UIColor colorWithHexString:@"F2AC3E"]).font([UIFont systemFontOfSize:16]);
  confer.text(@"注:可提现金额是您在“帮邦行司机-我的钱包-可提现账户”中的所有金额").textColor([UIColor colorWithHexString:@"666666"]);
  confer.paragraphStyle.lineSpacing(5);
}];
//刷新宽度自适应
NSDictionary *attributes = @{NSFontAttributeName:kFont(30),NSForegroundColorAttributeName: HEXCOLOR(0x333333)};
CGSize textSize = [[NSString stringWithFormat:@"%.2f",[self.payModel.charge_amt doubleValue]] boundingRectWithSize:CGSizeMake(0, 20) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;//LB宽度自适应
[self.moneyLB mas_remakeConstraints:^(MASConstraintMaker *make) {        
   make.left.mas_equalTo(self.payContentLB);
   make.top.mas_equalTo(self.payContentLB.mas_bottom).offset(15);
   make.width.mas_equalTo(textSize.width+30);//自适应
   make.height.mas_equalTo(40);
}];

10.tableview的代理和数据源的一套基本写法

1.遵循协议:<UITableViewDelegate,UITableViewDataSource>

2.创建:
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *topBgView;//头部视图
@property (nonatomic, strong) UIView *topContentView;
@property (nonatomic, strong) UILabel *yuqiMoneyLB;
@property (nonatomic, strong) UIView *footView;//尾部部视图
@property (nonatomic, strong) BBXQrCodeView *qrCodeImageView;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"标题";
    self.view.backgroundColor = [UIColor colorWithHexString:@"F1F2F4"];
    [self.topBgView addSubview:self.topContentView];
    [self.topContentView addSubview:self.yuqiMoneyLB];
    [self.footView addSubview:self.qrCodeImageView];//topBgView与footView不用添加,创建表格的时候设置了会自己添加
    [self.view addSubview:self.tableView];
}

//懒加载
//列表头部视图
- (UIView *)topBgView {
    if (!_topBgView) {
        _topBgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 140)];
    }
    return _topBgView;
}

- (UIView *)topContentView {
    if (!_topContentView) {
        _topContentView = [[UIView alloc]init];
        _topContentView.backgroundColor = BBXWhite;
        [self.topBgView addSubview:_topContentView];
        [_topContentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(15);
            make.left.mas_equalTo(10);
            make.centerX.mas_equalTo(self.topBgView);
            make.height.mas_equalTo(125);
        }];
        [_topContentView layoutIfNeeded];
        _topContentView.layer.cornerRadius = 12;
        _topContentView.layer.masksToBounds = YES;
        
        UIView *lineview = [[UIView alloc]init];
        [_topContentView addSubview:lineview];
        lineview.backgroundColor = BBXLineColor;
        [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(_topContentView);
            make.centerY.mas_equalTo(_topContentView);
            make.height.mas_equalTo(40);
            make.width.mas_equalTo(1);
        }];
        
        UILabel *leftTipLb = [[UILabel alloc]init];
        [_topContentView addSubview:leftTipLb];
        leftTipLb.textColor = BBXBlack;
        leftTipLb.font = kFont(15);
        leftTipLb.textAlignment = NSTextAlignmentCenter;
        leftTipLb.text = @"逾期欠款";
        [leftTipLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(_topContentView.mas_centerX).offset(0);
            make.height.mas_equalTo(20);
            make.bottom.mas_equalTo(_topContentView.mas_centerY).offset(-5);
        }];
    }
    return _topContentView;
}

- (UILabel *)yuqiMoneyLB {
    if (!_yuqiMoneyLB) {
        _yuqiMoneyLB = [[UILabel alloc]init];
        [self.topContentView addSubview:_yuqiMoneyLB];
        _yuqiMoneyLB.textColor = BBXBlack;
        _yuqiMoneyLB.font = kFont(27);
        _yuqiMoneyLB.textAlignment = NSTextAlignmentCenter;
        [_yuqiMoneyLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(self.topContentView.mas_centerX).offset(0);
            make.height.mas_equalTo(20);
            make.top.mas_equalTo(self.topContentView.mas_centerY).offset(5);
        }];
    }
    return _yuqiMoneyLB;
}

//列表尾部视图
- (UIView *)footView {
    if (!_footView) {
        _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 235)];
        _footView.userInteractionEnabled = YES;
        [_footView addSubview:self.qrCodeImageView];
    }
    return _footView;
}

-(BBXQrCodeView *)qrCodeImageView {//二维码(布局2种写法应该都可以)
    if (!_qrCodeImageView) {
        _qrCodeImageView = [[BBXQrCodeView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 235)];
        [self.footView addSubview:_qrCodeImageView];
//        [_qrCodeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(0);
//            make.top.mas_equalTo(0);
//            make.height.mas_equalTo(235);
//            make.centerX.mas_equalTo(self.footView);
//        }];
    }
    return _qrCodeImageView;
}

//表格
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];//1.常规类型:WithFrame:CGRectZero style:UITableViewStylePlain]; 2.分组类型:WithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BBXBgGray;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
        [_tableView registerClass:[BBXPayRecordListCell class] forCellReuseIdentifier:@"BBXPayRecordListCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"BBXBusFlightDetailOffBanCell" bundle:nil] forCellReuseIdentifier:@"BBXBusFlightDetailOffBanCell"];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            //make.top.bottom.left.right.equalTo(self.view);
        }];
        _tableView.tableHeaderView = self.topBgView;//头部视图
        _tableView.tableFooterView = self.footView;//尾部视图
    }
    return _tableView;
}
#pragma mark -- UITableViewDelegate && UITableViewDataSource
//多少个section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataArray.count;
}

//不同section多少个row
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 2;
    } else if (section == 1) {
        return 3;
    }
    
//    id obj = _dataArray[section];
//    if ([obj isKindOfClass:[BBXBusFlightStationModel class]]) {
//        BBXBusFlightStationModel *station = obj;
//        return station.offDetailInfo.passengerList.count;
//    }
//    if ([obj isKindOfClass:[OrderListModel class]]) {
//        OrderListModel *orderModel = obj;
//        if (orderModel.isMultipleOder) {
//            return orderModel.locations.multiple.count;
//        }else{
//            return 1;
//        }
//    }
    return 1;
}

//row高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
      return 100;
    } else if (indexPath.section == 1) {
        return 206;
    } else if (indexPath.section == 2) {
        OrderListModel *model = self.allArray[indexPath.row];
        CGFloat startHeight = [model.startAddress boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 78, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:18]} context:nil].size.height;
        CGFloat endHeight = [model.endAddress boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 78, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:18]} context:nil].size.height;
        if (isNullString(model.order_message)) {
              return startHeight + endHeight + 171;
        } else {
              return startHeight + endHeight + 171 + 28;
        }
    }

//    id obj = _dataArray[indexPath.section];
//    if ([obj isKindOfClass:[BBXBusFlightStationModel class]]) {
//        return 136.f;
//    } else if ([obj isKindOfClass:[OrderListModel class]]) {
//
//        OrderListModel *model = obj;
//
//        if (model.isMultipleOder) {
//            return 95;
//        }else{
//            if (model.order_status == 10) {// 已送
//                return 136.f;
//            } else if(model.order_status < 4){// 未上车
//                return 85;
//            }else{
//                return 136.f + 60;
//            }
//        }
//
//    }
    return 86;
}
//cell赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //第一种
    if (indexPath.section == 0) {
        GrabOrderListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GrabOrderListCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (self.dataArray.count>0) {//数组空处理最好判断数组有值的时候再赋值,否则无值容易奔溃
            OrderListModel *model = self.dataArray[indexPath.row];
            cell.model = model;
        }
        return cell;
    } else {
        BBXActionSheetCell *cell = (BBXActionSheetCell *)[tableView dequeueReusableCellWithIdentifier:[BBXActionSheetCell defaultReuseIdentifier] forIndexPath: indexPath];
        cell.title.text = @"取消";

        @weakify(self);
        [cell setRemoveBlock:^(id passItem) {//回调
            @strongify(self);
            if([passItem isKindOfClass:[YHMessageItem class]]) {
                 if (self.dataList.count == 0) {
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NO_UNREAD" object:nil];
                 }
                 [self.tableView reloadData];//刷新表格
            }
        }];
        return cell;
    }
    return nil;
    

    //第二种
    BBXAddBankcarCell *cell = [tableView dequeueReusableCellWithIdentifier:AddBankcarCellReuseId];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            cell.titleLB.text = @"姓名";
            cell.fillTextField.text = nameStr;
        } else if (indexPath.row == 1) {
            cell.titleLB.text = @"身份证号";
            cell.fillTextField.text = idCardStr;
        }
        cell.cellType = BBXAddBankcarCell_Type_Normal;
        cell.fillTextField.enabled = NO;
    } else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            _bankImgCell = [[BBXAddBankcarCell alloc]init];
            _bankImgCell.selectionStyle = UITableViewCellSelectionStyleNone;
            _bankImgCell.titleLB.text = @"开户行";
            _bankImgCell.cellType = BBXAddBankcarCell_Type_LeftImage;
            _bankImgCell.isFirst = YES;
            _bankImgCell.fillTextField.text = @"请选择开户银行";
            _bankImgCell.fillTextField.textColor = BBXBestLightGray;
            _bankImgCell.fillTextField.enabled = NO;
            return _bankImgCell;
        }
    }
    return cell;
    

    //第三种
    id obj = _dataArray[indexPath.section];//_dataArray是可变数组,包含添加了这两种模型的数据
    
    if ([obj isKindOfClass:[BBXBusFlightStationModel class]]) {
        
        static NSString *reuseBanCell = @"BBXBusNewOffBanCell";
        BBXBusNewOffBanCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseBanCell];
        BBXBusFlightStationModel *station = obj;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.passengerModel = station.offDetailInfo.passengerList[indexPath.row];
        [cell mapBtnBlock:^{
                    
        }];
        [cell payBtnBlock:^{// 代付款
            BBXBusPassengerOrderModel *model = [[BBXBusPassengerOrderModel alloc]init];
            model = station.offDetailInfo.passengerList[indexPath.row];
            [self helpPayWeixinWithPassenModel:model pModel:model.price_detail];
        }];
        return cell;
    } else if ([obj isKindOfClass:[OrderListModel class]]) {
        
        OrderListModel *model = obj;
        if (model.isMultipleOder) {
            Multiple *multipleModel = model.locations.multiple[indexPath.row];
            BBXBusMultipleOnTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MultipleOnCell"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell p_configureCellWithModel:multipleModel orderListModel:model viewTag:indexPath.row];
            cell.naviCallback = ^(Multiple * _Nonnull multipleModel) {
                OrderViewModel *orderViewModel = [[OrderViewModel alloc] initWithOrderModel:model];
                [[BBXMapNaviManager shareManager] beginMapNaviWithMultipleModel:multipleModel orderViewModel:orderViewModel viewTag:indexPath.row];//开始导航
                [BBXMapNaviManager shareManager].isOrderListJump = NO;
                
                [BBXMapNaviManager shareManager].carTakeUPBlock = ^{//导航里面的滑动接客按钮响应
                    BBXBillViewController *VC = [[BBXBillViewController alloc] init];
                    [self.navigationController pushViewController:VC animated:YES];
                };
            };
            return cell;
        } else {
            static NSString *reuseWangCell = @"BBXBusNewWangCell";
            BBXBusNewWangCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseWangCell];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = obj;
            cell.mapBtnBlock = ^{//导航
                
            };
            [cell payBtnBlock:^{// 代付款
                OrderListModel *model = [[OrderListModel alloc]init];
                model = obj;
                [self paymentWithOrderListModel:model];
            }];
            return cell;
        }
    }
    return nil;
}

// cell点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //第一种
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            NSLog(@"2");
        } else {
            NSLog(@"");
        }
    } else if (indexPath.section == 1) {
        NSLog(@"3");
    } else {
        NSLog(@"");
    }
    
    
    //第二种
    if (indexPath.section == 0) {
        
    } else {
        YHMessageItem *model = self.dataList[indexPath.row];
        if (model.homeShowAllmsg) {
            model.homeShowAllmsg = NO;
        } else {
            model.homeShowAllmsg = YES;
        }
        [self.tableView reloadData];//刷新表格
    }
    

    //第三种
    id obj = _dataArray[indexPath.section];
    if ([obj isKindOfClass:[BBXBusFlightStationModel class]]) {
        
        BBXBusFlightStationModel *station = obj;
        BBXBusPassengerDetailViewController *vc = [[BBXBusPassengerDetailViewController alloc] init];
        vc.detaiModel = station.onDetailInfo.passengerList[indexPath.row];
        [self.navigationController pushViewController:vc animated:YES];
    } else if ([obj isKindOfClass:[OrderListModel class]]) {
        
        OrderListModel *model = obj;
        if (model.order_status == 10) {//乘客已经下车了
            BBXOrderDetailViewController *VC = [[BBXOrderDetailViewController alloc]init];
            VC.model = model;
            [self.navigationController pushViewController:VC animated:YES];
        } else {
            BBXMapViewController *vc = [[BBXMapViewController alloc] init];
            vc.currentIsPickUp = NO;
            vc.isFromBus = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}
//section的Header(其他写法参考Footer,2者通用)
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    id obj = _dataArray[section];
    if ([obj isKindOfClass:[NSArray class]]) {
        return nil;
    }
    NSInteger count = 0;
    for (id obj in _dataArray) {
        if ([obj isKindOfClass:[NSArray class]]) {
            count++;
        }
    }
    if (section == count) {
        //继承UITableViewHeaderFooterView类,zx_loadFromNib为uiview的一个扩展写法,见下图
        BBXBusFlightDetailHeader *header = [BBXBusFlightDetailHeader zx_loadFromNib];
        header.orderCount = _dataArray.count - count;
        return header;
    }
    return nil;
    
    或者
    
    if ([obj isKindOfClass:[BBXBusFlightStationModel class]]) {
        BBXBusFlightDetailHeader *header = [BBXBusFlightDetailHeader zx_loadFromNib];
        header.stationModel = obj;
        return header;
    }
    
    if ([obj isKindOfClass:[OrderListModel class]]) {
        OrderListModel *model = obj;
        if (model.isMultipleOder) {
            UIView *backView = [[UIView alloc] init];
            backView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 83);
            backView.backgroundColor = kGrayBgColor;
            
            UIView *botView = [[UIView alloc] init];
            botView.backgroundColor = [UIColor whiteColor];
            [backView addSubview:botView];
            [botView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.equalTo(backView);
                make.height.mas_equalTo(33);
            }];
            
            UILabel *timeLabel = [self createLabelWithColor:@"666666" font:15];
            timeLabel.text = @"";
            [botView addSubview:timeLabel];
            [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(botView.mas_left).offset(20);
                make.centerY.equalTo(botView.mas_centerY);
            }];
            NSArray *array = [model.appoint_time_des_without_second componentsSeparatedByString:@" "];
            NSString *timeString =  array.count == 2 ? array[1] : @"";//时间
            NSString *typeString;
            if (model.order_type == OrderType_city) {
                typeString = @"市内包车";
            }else{
                typeString = @"包车";
            }
            timeLabel.text = [NSString stringWithFormat:@"%@  %@",timeString,typeString];
            return backView;
        } else {
            NSInteger count = 0;
            for (id obj in _dataArray) {
                if ([obj isKindOfClass:[BBXBusFlightStationModel class]]) {
                    count++;
                }
            }
            if (section == count) {
                BBXBusFlightDetailHeader *header = [BBXBusFlightDetailHeader zx_loadFromNib];
                header.orderCount = _dataArray.count - count;
                return header;
            }
        }
    }
    return nil;
}

//其中BBXBusFlightDetailHeader类继承UITableViewHeaderFooterView,Footer也可以继承这个类进行自定义
//BBXBusFlightDetailHeader.h文件:
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@class BBXBusFlightStationModel;

@interface BBXBusFlightDetailHeader : UITableViewHeaderFooterView

@property (nonatomic, strong) BBXBusFlightStationModel *stationModel;//班车站点

@property (nonatomic, assign) NSInteger orderCount;//网约车订单

@end

//BBXBusFlightDetailHeader.m文件:
#import "BBXBusFlightDetailHeader.h"
#import "BBXBusFlightStationModel.h"

@interface BBXBusFlightDetailHeader ()
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;//xib画的
@property (weak, nonatomic) IBOutlet UILabel *stationLabel;//xib画的
@end

@implementation BBXBusFlightDetailHeader

- (void)awakeFromNib {
    [super awakeFromNib];
    _timeLabel.layer.cornerRadius = 4.0;
    _timeLabel.layer.masksToBounds = YES;
}

- (void)setStationModel:(BBXBusFlightStationModel *)stationModel {
    _stationModel = stationModel;
    _stationLabel.text = stationModel.station_name;
    _timeLabel.backgroundColor = [UIColor clearColor];//新
    _timeLabel.textColor = HEXCOLOR(0xFF666666);
    _timeLabel.font = [UIFont systemFontOfSize:16];
    _stationLabel.textColor = HEXCOLOR(0xFF666666);
    _stationLabel.font = [UIFont systemFontOfSize:16];

    if (isNullString(stationModel.flights_dispatched_time)) {
        _timeLabel.text = @"补单站";
    } else {
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        NSDate *date = [fmt dateFromString:stationModel.flights_dispatched_time];
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSDateComponents *comps = [calendar components:NSCalendarUnitHour|NSCalendarUnitMinute fromDate:date];
        _timeLabel.text = [NSString stringWithFormat:@"%02li:%02li", (long)comps.hour, (long)comps.minute];
    }
}

- (void)setOrderCount:(NSInteger)orderCount {
    _orderCount = orderCount;
    _timeLabel.backgroundColor = HEXCOLOR(0xf3894d);
    _timeLabel.text = [NSString stringWithFormat:@"%li笔",(long)orderCount];
    _stationLabel.text = @"网约车拼车订单";
    _timeLabel.backgroundColor = [UIColor clearColor];//新
    _timeLabel.textColor = HEXCOLOR(0xFF666666);
    _timeLabel.font = [UIFont systemFontOfSize:16];
    _stationLabel.textColor = HEXCOLOR(0xFF666666);
    _stationLabel.font = [UIFont systemFontOfSize:16];
}

@end

//section的Header高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    id obj = _dataArray[section];
    if ([obj isKindOfClass:[BBXBusFlightStationModel class]]) {
        return section == 0 ? 50 : 50;
    }
    
    if ([obj isKindOfClass:[OrderListModel class]]) {
        OrderListModel *model = obj;
        if (model.isMultipleOder) {
            return 83;
        } else {
            NSInteger count = 0;
            for (id obj in _dataArray) {
                if ([obj isKindOfClass:[BBXBusFlightStationModel class]]) {
                    count++;
                }
            }
            return section == count ? 50 : 0.01;
        }
    }
    return 0.0001;
    
    或者
    
    id obj = _dataArray[section];
    if ([obj isKindOfClass:[NSArray class]]) {
        return section == 0 ? 50 : 0.01;
    } else {

        NSInteger count = 0;
        for (id obj in _dataArray) {
            if ([obj isKindOfClass:[NSArray class]]) {
                count++;
            }
        }
        if (section == count) {
            return 50;
        } else {
            return 0.01;
        }
    }
    return 0.01;

    或者
   
     //第一种
    if (section == 0) {
        return 10;
    } else if (section == 1) {
        return 0.01f;//也就是不要这个footer,设置成0.01不能设置成0,设置成0有问题
    } else {
        return 0.01f;
    }
}

//section的Footer
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    //第一种
    if (section == 0) {
        return [UIView new];//或者[[UIView alloc] init];
    } else if (section == 1) {
        return nil;//高度设置0.01也就是没有这个视图
    } else if (section == 2) {
        UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
        footView.backgroundColor = HEXCOLOR(0xF1F2F4);
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];//也可以masonry布局
        label.textColor = [UIColor grayColor];
        label.font = [UIFont systemFontOfSize:15];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"没有更多了";
        [footView addSubview:label];
        return footView;
    }
    return nil;
    
    
    //第二种
    id obj = _dataArray[section];
    if ([obj isKindOfClass:[OrderListModel class]]) {
        OrderListModel *model = obj;
        if (model.isMultipleOder) {
            WeakSelf;
            OrderViewModel *orderViewModel = [[OrderViewModel alloc] initWithOrderModel:model];

            UIView *backView = [[UIView alloc] init];
            backView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 130);

            UIView *topView = [[UIView alloc] init];
            topView.backgroundColor = [UIColor whiteColor];
            [backView addSubview:topView];
            [topView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(backView.mas_left).offset(0);
                make.right.equalTo(backView.mas_right).offset(0);
                make.top.equalTo(backView.mas_top);
                make.height.mas_equalTo(74);
            }];

            //左滑操作控件
            BBXBusGradientStatusSlider *gradientSlider = [[BBXBusGradientStatusSlider alloc] initWithFrame:CGRectMake(0, 74, SCREEN_WIDTH, 50)];
            [gradientSlider setHidden:YES];
            [backView addSubview:gradientSlider];
            [gradientSlider updateSliderText:@"送达乘客" WithStatus:NO];
            __weak typeof(gradientSlider)weakGradientSlider = gradientSlider;
            @weakify(self);
            //左滑操作控件回调方法
            [weakGradientSlider setSwitchEventOccuBlock:^(NSInteger execStep){
                BBXBillViewController *VC = [[BBXBillViewController alloc] init];//跳转到付款界面
                [self.navigationController pushViewController:VC animated:YES];
            }];
            return backView;
        }
    }
    return nil;
}

//section的Footer高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    //第一种
    if (section == 0) {
        return 10;
    } else if (section == 1) {
        return 0.01f;//也就是不要这个footer,设置成0.01不能设置成0,设置成0有问题
    } else if (section == 2) {
        return 130;
    } else {
        return 0.01f;
    }

   //第二种
   id obj = _dataArray[section];
    if ([obj isKindOfClass:[OrderListModel class]]) {
        OrderListModel *model = obj;
        if (model.isMultipleOder) {
            return 130;
        }
    }
    return 0.001f;
}
BBXBusFlightDetailHeader的Xib zx_loadFromNib 效果图 注册表格的header header实现 封装的header.h 封装的header.m

11.数据处理:尽量在model和cell中去处理

tableview数据的展示,逻辑处理以及UI的高度变化等最好都关联model在cell中去处理,最后再在VC中去调用即可,这样保证VC干净简洁。

12.Xcode的各种历史版本下载

链接:https://developer.apple.com/download/more/

Xcode10.1运行老版本项目报错 libstdc++库 前往文件夹 Xcode文件地址

文件1:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/

文件2:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/

文件3:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/

文件4:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/

补充:

在Xcode编译的时候,可能会遇到报这个错误"library not found for - ",这是因为缺少一些库;如果是使用第三方库造成的则用pod install 命令重新安装,成功后再打开Xcode编译项目;如果是像上述描述的因为系统库则需要下载相应的库对应添加再重新编译即可;相关链接:https://www.cnblogs.com/Hakim/p/6555933.html

13.iOS真机调试包下载

解决低版本Xcode不支持高版本iOS真机调试的问题;如图所示,如果手机系统很高,Xcode版本较低不支持就会报这个提示,解决方式就是下载相应的真机调试包加入即可。拖到存放的文件夹,路径是:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
真机包下载地址:https://github.com/wanglei11413/iOS--/tree/master
解决说明链接:https://blog.csdn.net/xiangzhihong8/article/details/78360091

注意:有时候比如当前手机更新最新系统为15.3.1,但是网上能下载到的真机包最新为15.2,这个时候可以下载15.2真机包拖入相应的存放地址,再手动将15.2的文件名改成15.3如下图,这样也能成功运行15.3.1系统的手机。

不匹配运行的报错 下载的真机包15.2拖入相应的地方 手动将实际15.2的真机包改成15.3

14.Xcode10与iOS12适配以及解决方案(新xcode运行老xcode项目 --> 跑不起)

  • 1.添加的tbd和dylib的文件参考跑不起和libstdc--master文件夹

  • 2.添加libstdc++.6.0.9.tbd,libstdc++.6.tbd,libstdc++.tbd的路径(每个地址都添加libstdc++.6.0.9.tbd,其他看情况)
    1).模拟器添加地址(可以终端open或者文件夹前往):/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/
    2).真机添加地址:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/

  • 3.添加libstdc++.6.0.9.dylib,libstdc++.6.dylib,libstdc++.dylib的路径(每个地址都添加这三个)(如果tbd添加了,dylib没添加会报错:报错2)
    1).真机地址(同上面的真机地址):/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/
    2).模拟器地址(同上面的模拟器地址):/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/
    3).在RuntimeRoot的lib里面的地址(不添加也可以正常运行,看情况):/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/

添加的文件 dylib文件 模拟器文件 真机文件 报错1 报错2
上一篇 下一篇

猜你喜欢

热点阅读