周记总结 2017-03-17记下


UITableViewCell左侧会有默认15像素的空白

在iOS7中,UITableViewCell左侧会有默认15像素的空白。这时候,设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。

但是在ios8中,设置setSeparatorInset:UIEdgeInsetsZero 已经不起作用了。下面是解决办法

首先在viewDidLoad方法加入以下代码:

if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {

    [self.tableView setSeparatorInset:UIEdgeInsetsZero];

}

if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {

    [self.tableView setLayoutMargins:UIEdgeInsetsZero];

}

然后在UITableView的代理方法中加入以下代码

– (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {

        [cell setSeparatorInset:UIEdgeInsetsZero];

    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

        [cell setLayoutMargins:UIEdgeInsetsZero];

    }

}

封装View注意事项

封装view的时候要注意在-(void)layoutSubviews中重写子视图的frame


 Block的书写格式

Block的格式:  ^ + 返回值类型(可以省略) + (参数)(如果没有参数,可以省略) + {表达式}

     Block变量格式: 返回值类型(不可省略, 最少void) + (^变量名称) + (参数) (不可省略, 至少()).  格式和函数指针很相似,只是把*改成了^.

修复在没有获得位置就连接Socket,上传位置信息的bug


模拟器的坑

如果用模拟器,有时候会选择直接电脑键盘输入,但这时候需要考虑很多问题。因为键盘弹出事件就消失了。


关于OC在浮点数.f说明

1.如果是赋给CGFloat类型,则加不加f后缀都是一样的。

2.如果是赋给doublefloat类型,就要考虑精度的问题。不加f后缀的话类型为double8字节,加f后缀的话类型为float4字节。


一种单例写法(dispatch_once_t)的单例用法

+ (AccountManager *)sharedManager
{
        static AccountManager *sharedAccountManagerInstance = nil;
        static dispatch_once_t predicate;
        dispatch_once(&predicate, ^{
                sharedAccountManagerInstance = [[self alloc] init];
        });
    return sharedAccountManagerInstance;
}

Block会复制到堆的情况

1.调用Blockcopy实例方法

2.Block作为函数返回值时

3.Block赋值给附有_strong修饰符id类型的类或Block类成员变量时

3.在方法名中含有usingBlockCocoa框架方法或Grand Central DispatchAPI中传递Block


对使用_block变量避免循环引用的方法和使用__weak修饰符及__unsafe_unretained修饰符避免循环引用的方法做个比较

1.通过__block变量可控制对象的持有期间

2.在不能使用__weak修饰符的环境中不使用__unsafe)unretained修饰符即可(不必担心悬垂指针)

3.在执行Block时可动态地决定是否将nil或其他对象赋值在__block变量中

4.为避免循环引用必须执行Block


本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。

本站由 @shyiuanchen 创建,使用 Stellar 作为主题。