1:用xib创建tableview的header,footView的时候,不能准确计算出xib的高度。
解决:自己计算出来,先设置带有frame的view给header,footView。再设置xib创建出来添加到view上。
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH , footViewHeight)];
self.mTableView.tableFooterView = footerView;
self.visaFootView = [AYVisaFootView gainFootViewFromXib];
self.visaFootView.frame = CGRectMake(0, 0, self.mTableView.bounds.size.width, footViewHeight);
[footerView addSubview:self.visaFootView];
2:用reachability判断网络连接状态时,网络连接变化都会监听到。(但是在模拟器上会出现不准确的现象)
+ (NSInteger)getNetStatus:(NetworkChangedBlock)block
{
__block NSInteger code = 0;
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
//当网络状态发生变化时会调用这个block
switch (status) {
case AFNetworkReachabilityStatusReachableViaWiFi:
code = 1;
NSLog(@"WiFi");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
code = 2;
NSLog(@"手机网络");
break;
case AFNetworkReachabilityStatusNotReachable:
code = -1;
NSLog(@"没有网络");
break;
case AFNetworkReachabilityStatusUnknown:
code = 0;
NSLog(@"未知网络");
break;
default:
break;
}
if (block) {
block(code);
}
}];
[manager startMonitoring];
return code;
}
3:AFN的坑,当网络连接正常,服务器端异常。服务器回复正常后,APP端还是请求异常。
这是因为AFN缓存了Url的Response;
解决办法:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
4:xib进行布局需要动画时,拉出约束,进行约束的更改,用[UIView animateWithDuration:0.2 animations:^{}
进行动画,在block里面调用,父类view的layoutIfNeeded;记住一定是父类的才会起作用.
5:ios 将连接字符串复制到剪贴板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = str;//->需要复制的字符串
5:swift 数组的快速排序
let array = [3,5,6,1,0]
let res = array.sorted( by: > )
5:设置滚动位置,不影响输入
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
CGPoint point = [_mScrollView convertPoint:textField.bounds.origin fromView:_viewSplitPay];
CGFloat offsetY = SCREEN_HEIGHT-216.0-64-40-20;
if (SCREEN_WIDTH == 414) {
offsetY = offsetY - 10;
}
[UIView animateWithDuration:.3 animations:^{
_mScrollView.contentOffset = CGPointMake(0, point.y-offsetY);
}];
return YES;
}