1:Masonry快速查看报错小技巧

self.statusLabel = [UILabel new];
[self.contentView addSubview:self.statusLabel];
MASAttachKeys(self.statusLabel); [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(15.0f);
make.left.equalTo(self.contentView).offset(.f);
make.height.equalTo();
make.bottom.equalTo(self.contentView);
}];

注意:MASAttachKeys会显示出比较明了的错误信息;

2:iOS跳转到系统设置

注意:想要实现应用内跳转到系统设置界面功能,需要先在Targets-Info-URL Types-URL Schemes中添加prefs

跳转到WIFI设置
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:@"prefs:root=WIFI"]])
{
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
} 跳转到蓝牙
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]])
{
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]];
} 跳转到通用
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:@"prefs:root=General"]])
{
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"prefs:root=General"]];
} 跳转到关于本机
if ([[UIApplication sharedApplication]
canOpenURL:[NSURLURLWithString:
@"prefs:root=General&path=About"]])
{
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"prefs:
root=General&path=About"]];
} 跳转到定位服务
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:@"prefs:
root=LOCATION_SERVICES"]])
{
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"prefs:
root=LOCATION_SERVICES"]];
} 跳转到通知
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:@"prefs:
root=NOTIFICATIONS_ID"]])
{
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"prefs:
root=NOTIFICATIONS_ID"]];
}

 3:UITableView section随着cell滚动 

实现UITableView 的下面这个方法,
#pragma mark - Scroll
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat sectionHeaderHeight = ;
//固定section 随着cell滚动而滚动
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=) { scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, , , ); } else if (scrollView.contentOffset.y>=sectionHeaderHeight) { scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, , , ); } }

4:TableView如何刷新指定的cell 或section  

//一个section刷新    

NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:];    

[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];    

//一个cell刷新    

NSIndexPath *indexPath=[NSIndexPath indexPathForRow: inSection:];    

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];  

 5:TableView另一种实现隔行空白的效果

增加总体条数,然后再求余判断

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CELL_ID2 = @"SOME_STUPID_ID2";
// even rows will be invisible
if (indexPath.row % == )
{
UITableViewCell * cell2 = [tableView dequeueReusableCellWithIdentifier:CELL_ID2]; if (cell2 == nil)
{
cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CELL_ID2];
[cell2.contentView setAlpha:];
[cell2 setUserInteractionEnabled:NO]; // prevent selection and other stuff
}
return cell2;
} [ccTableView setBackgroundColor:[UIColor clearColor]];
cardsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cardsCell"]; if(cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cardsCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:];
} // Use indexPath.row/2 instead of indexPath.row for the visible section to get the correct datasource index (number of rows is increased to add the invisible rows)
NSString *nmCard = [[self.cards valueForKeyPath:@"cards.name"] objectAtIndex:(indexPath.row/)];
cell.descCardLabel.text = nmCard; return cell;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // two times minus one (invisible at even rows => visibleCount == invisibleCount+1)
return [[self.cards valueForKeyPath:@"cards"] count] * - ;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row % == )
return ;
return ;
}

 6:滚动TableView,滚动到指定的位置

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
typedef enum {
UITableViewScrollPositionNone,
UITableViewScrollPositionTop,
UITableViewScrollPositionMiddle,
UITableViewScrollPositionBottom
} UITableViewScrollPosition;

 7:iOS-检测UI主线程小工具

在iOS开发中需要保证所有UI操作一定是在主线程进行,通过 hook UIView的-setNeedsLayout,-setNeedsDisplay,-setNeedsDisplayInRect三个方法,确保它们都是在主线程执行。

#import "UIView+NBUIKitMainThreadGuard.h"
#import <objc/runtime.h> static inline void swizzling_exchangeMethod(Class clazz ,SEL originalSelector, SEL swizzledSelector){
Method originalMethod = class_getInstanceMethod(clazz, originalSelector);
Method swizzledMethod = class_getInstanceMethod(clazz, swizzledSelector); BOOL success = class_addMethod(clazz, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (success) {
class_replaceMethod(clazz, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
} @implementation UIView (NBUIKitMainThreadGuard) +(void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ SEL needsLayoutOriginalSelector = @selector(setNeedsLayout);
SEL needsLayoutSwizzleSelector = @selector(guard_setNeedsLayout);
swizzling_exchangeMethod(self, needsLayoutOriginalSelector,needsLayoutSwizzleSelector); SEL needsDisplaOriginalSelector = @selector(setNeedsDisplay);
SEL needsDisplaSwizzleSelector = @selector(guard_setNeedsDisplay);
swizzling_exchangeMethod(self, needsDisplaOriginalSelector,needsDisplaSwizzleSelector); SEL needsDisplayInRectOriginalSelector = @selector(setNeedsDisplayInRect:);
SEL needsDisplayInRectSwizzleSelector = @selector(guard_setNeedsDisplayInRect:);
swizzling_exchangeMethod(self, needsDisplayInRectOriginalSelector,needsDisplayInRectSwizzleSelector); });
} - (void)guard_setNeedsLayout
{
[self UIMainThreadCheck];
[self guard_setNeedsLayout];
} - (void)guard_setNeedsDisplay
{
[self UIMainThreadCheck];
[self guard_setNeedsDisplay];
} - (void)guard_setNeedsDisplayInRect:(CGRect)rect
{
[self UIMainThreadCheck];
[self guard_setNeedsDisplayInRect:rect];
} - (void)UIMainThreadCheck
{
NSString *desc = [NSString stringWithFormat:@"%@", self.class];
NSAssert([NSThread isMainThread], desc);
} @end

IOS开发基础知识--碎片40的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  3. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  4. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  5. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  6. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  7. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

  8. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

  9. IOS开发基础知识--碎片19

    1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...

随机推荐

  1. javascript运动系列第七篇——鼠标跟随运动

    × 目录 [1]眼球转动 [2]苹果菜单[3]方向跟随 前面的话 运动除了直线运动和曲线运动两种运动形式外,还有一种运动形式是鼠标跟随运动,而这种跟随运动需要用到三角函数的相关内容或者需要进行比例运算 ...

  2. iOS开发之SQLite-C语言接口规范(二) —— Prepared Your SQL Statements

    在<SQLite的C语言接口规范(一)>中介绍了如何去连接打开数据库,本篇博客就介绍如何操作数据库,本篇主要给出了如何执行数据库查询语句(Select), 然后遍历结果集.本篇博客就直接使 ...

  3. Git代码管理工具

    Git代码管理工具 Git 是分布式的源代码管理工具,这点区别于svn -让源代码可以被追溯,主要是记录了每次的更新了什么,如果新版本不想用,那么则可以退回之前的版本 -Git 是Linux之父当年为 ...

  4. Java ConcurrentHashMap Example and Iterator--转

    原文地址:http://www.journaldev.com/122/java-concurrenthashmap-example-iterator#comment-27448 Today we wi ...

  5. 项目中遇到的Integer问题--转

    Integer类型值相等或不等分析 http://www.cnblogs.com/zzllx/p/5778470.html 看到博客园一位博友写的面试问题,其中一题是 Integer a = 1; I ...

  6. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  7. Sql Server之使用T_SQL创建,修改,查看数据库信息

    一.使用Transact_SQL创建数据库 Transact_SQL语法如下:  create database database_name   [ on     [primary]  [<fi ...

  8. 关于从JSP页面插入数据到数据库中乱码问题的解决

    问题描述:最近我在写一个j2ee的留言板系统模块,遇到了一个非常让我头大的问题,当我从JSP页面输入数据后,通过hibernate中的业务逻辑类HQL语句把这个数据插入到本地的mysql数据库中,可是 ...

  9. 【Android】Fragment懒加载和ViewPager的坑

    效果 老规矩,先来看看效果 ANDROID和福利两个Fragment是设置的Fragment可见时加载数据,也就是懒加载.圆形的旋转加载图标只有一个,所以,如果当前Fragment正处于加载状态,在离 ...

  10. [AngularJS] AngularJS系列(6) 中级篇之ngResource

    目录 $http ngResource $http几乎是所有ng开发中,都会用到的服务.本节将重点说下$http 与 ngResource $http 使用:$http(config); 参数: me ...