1.tableView的分割線默認(rèn)頂不到邊穴店,但有時(shí)我們需要頂?shù)竭叀?/h6>
#pragma mark - 分割線頂?shù)竭?-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath: (NSIndexPath *)indexPat{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
2.去掉多余cell
[self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
3.讓cell選中時(shí)不變色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
4.去掉指定行cell分割線
if (indexPath.row == 4) {
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
5.取消cell選中狀態(tài)
[tableView deselectRowAtIndexPath:indexPath animated:YES]
6.cell動(dòng)畫出現(xiàn)效果
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
CATransform3D rotation;
rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
rotation.m34 = 1.0/ -600;
cell.layer.transform = rotation;
cell.layer.shadowColor = [[UIColor blackColor]CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
cell.alpha = 0;
[UIView beginAnimations:@"rotation" context:NULL];
[UIView setAnimationDuration:0.8];
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
cell.layer.shadowOffset = CGSizeMake(0, 0);
[UIView commitAnimations];
/*
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.2, 0.2, 1)];
scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 1)];
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[cell.layer addAnimation:scaleAnimation forKey:@"transform"];
*/
}
7.獲取當(dāng)前cell
FirstCell *cell = (FirstCell *)[self.tableView cellForRowAtIndexPath:indexPath];
8.更新某個(gè)cell數(shù)據(jù)
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
9.cell點(diǎn)擊完取消灰色背景
[tableView deselectRowAtIndexPath:indexPath animated:YES];
10.點(diǎn)擊View阵谚,讓鍵盤消失
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
11.拼音首字母排序
NSArray *resultArray = [_dataArr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
return [obj1 compare:obj2 options:NSNumericSearch];
}];
12.判斷一個(gè)時(shí)間距離當(dāng)前時(shí)間過(guò)去了多久
- (NSString *) compareCurrentTime:(NSString *)theTime
{
//字符串轉(zhuǎn)日期格式
NSDateFormatter *format=[[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *fromdate=[format dateFromString:theTime];
//有時(shí)差添加這個(gè)
//NSTimeZone *fromzone = [NSTimeZone systemTimeZone];
//NSInteger frominterval = [fromzone secondsFromGMTForDate: fromdate];
//NSDate *fromDate = [fromdate dateByAddingTimeInterval: frominterval];
NSTimeInterval timeInterval = [fromdate timeIntervalSinceNow];
timeInterval = -timeInterval;
long temp = 0;
NSString *result;
if (timeInterval < 60) {
result = [NSString stringWithFormat:@"1分鐘"];
}else if((temp = timeInterval/60) <60){
result = [NSString stringWithFormat:@"%ld分前",temp];
}else if((temp = temp/60) <24){
result = [NSString stringWithFormat:@"%ld小前",temp];
}else if((temp = temp/24) <30){
result = [NSString stringWithFormat:@"%ld天前",temp];
}else if((temp = temp/30) <12){
result = [NSString stringWithFormat:@"%ld月前",temp];
}else{
temp = temp/12;
result = [NSString stringWithFormat:@"%ld年前",temp];
}
return result;
}
13.獲取時(shí)間戳
//獲取系統(tǒng)當(dāng)前的時(shí)間戳
- (NSString *)getTime{
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: dat];
NSDate *localeDate = [dat dateByAddingTimeInterval: interval];
NSTimeInterval a=[localeDate timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%.0f", a];//轉(zhuǎn)為字符型
return timeString;
}
14.二進(jìn)制轉(zhuǎn)JSON
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
15.在AppDelegate中設(shè)置NavigationBar
if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) {
//背景顏色
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
//設(shè)置字體顏色衔憨,font,大小
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@ "HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
}
16.登陸時(shí)判斷是不是手機(jī)號(hào)
//注冊(cè)手機(jī)號(hào)判斷
NSString *phoneRegex = @"1[3|5|7|8|][0-9]{9}";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
BOOL isMatch = [phoneTest evaluateWithObject:_phoneNumber.text];
if (isMatch) {
NSLog(@"手機(jī)號(hào)正確");
}
17.判斷郵箱正確宴抚?
-(BOOL)isValidateEmail:(NSString *)email {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
18.退出登陸后跳回主頁(yè)
[self.tabBarController setSelectedIndex:0];
[self.navigationController popToRootViewControllerAnimated:YES];
19.設(shè)置底部標(biāo)簽欄背景
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, W, 49)];
backView.backgroundColor = BASECOLOR;
[self.tabBarController.tabBar insertSubview:backView atIndex:0];
self.tabBarController.tabBar.opaque = YES;
20.設(shè)置導(dǎo)航欄不透明
self.navigationController.navigationBar.translucent = NO;
self.tabBarController.tabBar.translucent = NO;
21.設(shè)置陰影
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
view.backgroundColor = [UIColor whiteColor];
view.layer.shadowOpacity = 0.8;
view.layer.shadowOffset = CGSizeMake(1.0, 1.0);
[self.view addSubview:view];
self.view.backgroundColor = [UIColor whiteColor];
22.跳轉(zhuǎn)下一頁(yè)勒魔,隱藏底部bar
- (void)nextBtnClicked:(UIButton *)btn{
SetUpController *setVC = [[SetUpController alloc] init];
//隱藏底部狀態(tài)欄
[setVC setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:setVC animated:YES];
}
23.發(fā)送通知,舉個(gè)例子菇曲,用戶登錄成功冠绢,通知其他頁(yè)面新用戶登錄
//登陸成功之后發(fā)起通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"此通知標(biāo)識(shí)" object:nil];
//寫在需要刷新數(shù)據(jù)的頁(yè)面
//注冊(cè)通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refresh) name:kNotificationIntrist object:nil];
//在該頁(yè)面刪除通知
- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:@"此通知標(biāo)識(shí)"];
}
24.block傳值
/*a頁(yè)面.h代碼*/
#import <UIKit/UIKit.h>
//評(píng)價(jià)完成刷新頁(yè)面block
typedef void(^commentOverBlock)(BOOL reload);
@interface CommentController :UIViewController
@property (nonatomic,strong) commentOverBlock commentSuccessBlock;
- (void)returnCommentBlock:(commentOverBlock)block;
/*a頁(yè)面.m代碼*/
#import "CommentController.h"
@implementation CommentController
- (void)returnCommentBlock:(commentOverBlock)block{
self.commentSuccessBlock = block;
}
#pragram mark - 評(píng)論完成執(zhí)行方法
- (void)hadCommendSuccess{
self.commentSuccessBlock(YES);
}
/*-------------------------------------------------------------------*/
/*b頁(yè)面代碼*/
CommentController *commentVC = [[CommentController alloc] init];
[commentVC returnCommentBlock:^(BOOL reload) {
//刷新頁(yè)面
}];
25.字體導(dǎo)入
1.先下載需要的.ttf字體包,然后添加到項(xiàng)目中
2.在info.plist文件中添加Fonts provided by application字段常潮,在該字段下弟胀,添加字體包名即可
26.全局token
//寫入
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setObject:uid forKey:@"uid"];
[ud synchronize];
//取出
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSString *uid = [ud objectForKey:@"uid"];
27.同時(shí)進(jìn)行多個(gè)網(wǎng)絡(luò)請(qǐng)求,兩個(gè)請(qǐng)求都完成后執(zhí)行下面操作
//信號(hào)量
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
//創(chuàng)建全局并行
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//任務(wù)一
dispatch_group_async(group, queue, ^{
[self postRequest:^{ //這個(gè)block是此網(wǎng)絡(luò)任務(wù)異步請(qǐng)求結(jié)束時(shí)調(diào)用的,代表著網(wǎng)絡(luò)請(qǐng)求的結(jié)束.
//一個(gè)任務(wù)結(jié)束時(shí)標(biāo)記一個(gè)信號(hào)量
dispatch_semaphore_signal(semaphore);
}];
});
//任務(wù)二
dispatch_group_async(group, queue, ^{
[self postCommentListRequest:^{
dispatch_semaphore_signal(semaphore);
}];
});
dispatch_group_notify(group, queue, ^{
// 三個(gè)請(qǐng)求對(duì)應(yīng)三次信號(hào)等待
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
NSLog(@"ok啦,可以執(zhí)行下面代碼");
});
- (void)postRequest:(void(^)())finish{
VideoDetailViewModel *model = [[VideoDetailViewModel alloc] init];
[model getModel:self.parametersModel videoDetailInfo:^(NSArray *array) {
finish();
} Failure:^(NSError *error) {
finish();
}];
}
- (void)postCommentListRequest:(void(^)())finish{
VideoDetailViewModel *model = [[VideoDetailViewModel alloc] init];
[model getModel:self.parametersModel ChatListModel:^(NSArray *array, BOOL haveMore) {
finish();
} Failure:^(NSError *error) {
finish();
}];
}
28.AFNetWorking設(shè)置返回json格式:
//設(shè)置請(qǐng)求返回格式數(shù)據(jù)為Json
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/plain", @"text/html", nil];
29.AFNetWorking設(shè)置請(qǐng)求超時(shí)
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
manager.requestSerializer.timeoutInterval = 15.f;
30.解析AFNetWorking返回error
NSLog(@"%@",[[NSString alloc] initWithData:error.userInfo[@"com.alamofire.serialization.response.error.data"] encoding:NSUTF8StringEncoding]);
31.Navgation返回指定頁(yè)
UIViewController *viewCtl = self.navigationController.viewControllers[2];
[self.navigationController popToViewController:viewCtl animated:YES];
32.tableview section header高度設(shè)置問題
#pragma mark - 分割線頂?shù)竭?-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath: (NSIndexPath *)indexPat{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
[self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.row == 4) {
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES]
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
CATransform3D rotation;
rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
rotation.m34 = 1.0/ -600;
cell.layer.transform = rotation;
cell.layer.shadowColor = [[UIColor blackColor]CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
cell.alpha = 0;
[UIView beginAnimations:@"rotation" context:NULL];
[UIView setAnimationDuration:0.8];
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
cell.layer.shadowOffset = CGSizeMake(0, 0);
[UIView commitAnimations];
/*
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.2, 0.2, 1)];
scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 1)];
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[cell.layer addAnimation:scaleAnimation forKey:@"transform"];
*/
}
FirstCell *cell = (FirstCell *)[self.tableView cellForRowAtIndexPath:indexPath];
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
NSArray *resultArray = [_dataArr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
return [obj1 compare:obj2 options:NSNumericSearch];
}];
- (NSString *) compareCurrentTime:(NSString *)theTime
{
//字符串轉(zhuǎn)日期格式
NSDateFormatter *format=[[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *fromdate=[format dateFromString:theTime];
//有時(shí)差添加這個(gè)
//NSTimeZone *fromzone = [NSTimeZone systemTimeZone];
//NSInteger frominterval = [fromzone secondsFromGMTForDate: fromdate];
//NSDate *fromDate = [fromdate dateByAddingTimeInterval: frominterval];
NSTimeInterval timeInterval = [fromdate timeIntervalSinceNow];
timeInterval = -timeInterval;
long temp = 0;
NSString *result;
if (timeInterval < 60) {
result = [NSString stringWithFormat:@"1分鐘"];
}else if((temp = timeInterval/60) <60){
result = [NSString stringWithFormat:@"%ld分前",temp];
}else if((temp = temp/60) <24){
result = [NSString stringWithFormat:@"%ld小前",temp];
}else if((temp = temp/24) <30){
result = [NSString stringWithFormat:@"%ld天前",temp];
}else if((temp = temp/30) <12){
result = [NSString stringWithFormat:@"%ld月前",temp];
}else{
temp = temp/12;
result = [NSString stringWithFormat:@"%ld年前",temp];
}
return result;
}
//獲取系統(tǒng)當(dāng)前的時(shí)間戳
- (NSString *)getTime{
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: dat];
NSDate *localeDate = [dat dateByAddingTimeInterval: interval];
NSTimeInterval a=[localeDate timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%.0f", a];//轉(zhuǎn)為字符型
return timeString;
}
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) {
//背景顏色
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
//設(shè)置字體顏色衔憨,font,大小
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@ "HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
}
//注冊(cè)手機(jī)號(hào)判斷
NSString *phoneRegex = @"1[3|5|7|8|][0-9]{9}";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
BOOL isMatch = [phoneTest evaluateWithObject:_phoneNumber.text];
if (isMatch) {
NSLog(@"手機(jī)號(hào)正確");
}
-(BOOL)isValidateEmail:(NSString *)email {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
[self.tabBarController setSelectedIndex:0];
[self.navigationController popToRootViewControllerAnimated:YES];
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, W, 49)];
backView.backgroundColor = BASECOLOR;
[self.tabBarController.tabBar insertSubview:backView atIndex:0];
self.tabBarController.tabBar.opaque = YES;
self.navigationController.navigationBar.translucent = NO;
self.tabBarController.tabBar.translucent = NO;
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
view.backgroundColor = [UIColor whiteColor];
view.layer.shadowOpacity = 0.8;
view.layer.shadowOffset = CGSizeMake(1.0, 1.0);
[self.view addSubview:view];
self.view.backgroundColor = [UIColor whiteColor];
- (void)nextBtnClicked:(UIButton *)btn{
SetUpController *setVC = [[SetUpController alloc] init];
//隱藏底部狀態(tài)欄
[setVC setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:setVC animated:YES];
}
//登陸成功之后發(fā)起通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"此通知標(biāo)識(shí)" object:nil];
//寫在需要刷新數(shù)據(jù)的頁(yè)面
//注冊(cè)通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refresh) name:kNotificationIntrist object:nil];
//在該頁(yè)面刪除通知
- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:@"此通知標(biāo)識(shí)"];
}
/*a頁(yè)面.h代碼*/
#import <UIKit/UIKit.h>
//評(píng)價(jià)完成刷新頁(yè)面block
typedef void(^commentOverBlock)(BOOL reload);
@interface CommentController :UIViewController
@property (nonatomic,strong) commentOverBlock commentSuccessBlock;
- (void)returnCommentBlock:(commentOverBlock)block;
/*a頁(yè)面.m代碼*/
#import "CommentController.h"
@implementation CommentController
- (void)returnCommentBlock:(commentOverBlock)block{
self.commentSuccessBlock = block;
}
#pragram mark - 評(píng)論完成執(zhí)行方法
- (void)hadCommendSuccess{
self.commentSuccessBlock(YES);
}
/*-------------------------------------------------------------------*/
/*b頁(yè)面代碼*/
CommentController *commentVC = [[CommentController alloc] init];
[commentVC returnCommentBlock:^(BOOL reload) {
//刷新頁(yè)面
}];
1.先下載需要的.ttf字體包,然后添加到項(xiàng)目中
2.在info.plist文件中添加Fonts provided by application字段常潮,在該字段下弟胀,添加字體包名即可
//寫入
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setObject:uid forKey:@"uid"];
[ud synchronize];
//取出
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSString *uid = [ud objectForKey:@"uid"];
//信號(hào)量
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
//創(chuàng)建全局并行
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//任務(wù)一
dispatch_group_async(group, queue, ^{
[self postRequest:^{ //這個(gè)block是此網(wǎng)絡(luò)任務(wù)異步請(qǐng)求結(jié)束時(shí)調(diào)用的,代表著網(wǎng)絡(luò)請(qǐng)求的結(jié)束.
//一個(gè)任務(wù)結(jié)束時(shí)標(biāo)記一個(gè)信號(hào)量
dispatch_semaphore_signal(semaphore);
}];
});
//任務(wù)二
dispatch_group_async(group, queue, ^{
[self postCommentListRequest:^{
dispatch_semaphore_signal(semaphore);
}];
});
dispatch_group_notify(group, queue, ^{
// 三個(gè)請(qǐng)求對(duì)應(yīng)三次信號(hào)等待
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
NSLog(@"ok啦,可以執(zhí)行下面代碼");
});
- (void)postRequest:(void(^)())finish{
VideoDetailViewModel *model = [[VideoDetailViewModel alloc] init];
[model getModel:self.parametersModel videoDetailInfo:^(NSArray *array) {
finish();
} Failure:^(NSError *error) {
finish();
}];
}
- (void)postCommentListRequest:(void(^)())finish{
VideoDetailViewModel *model = [[VideoDetailViewModel alloc] init];
[model getModel:self.parametersModel ChatListModel:^(NSArray *array, BOOL haveMore) {
finish();
} Failure:^(NSError *error) {
finish();
}];
}
//設(shè)置請(qǐng)求返回格式數(shù)據(jù)為Json
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/plain", @"text/html", nil];
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
manager.requestSerializer.timeoutInterval = 15.f;
NSLog(@"%@",[[NSString alloc] initWithData:error.userInfo[@"com.alamofire.serialization.response.error.data"] encoding:NSUTF8StringEncoding]);
UIViewController *viewCtl = self.navigationController.viewControllers[2];
[self.navigationController popToViewController:viewCtl animated:YES];
這個(gè)應(yīng)該是新手遇到的比較多的喊式。起因是iOS奇葩的邏輯孵户,如果你設(shè)置header(或者footer)高度是0的話,系統(tǒng)會(huì)認(rèn)為你沒設(shè)置岔留,然后將其設(shè)置為40.f夏哭。所以需要將其設(shè)置為一個(gè)較小的數(shù)
_tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.001f)];