iOS笔记

1. LaunchImage

LaunchImage图片对UI会产生影响,LaunchImage一定要确保尺寸跟格式完全正确

2. UIViewAutoresize
UIViewAutoresizingNone 不会随父视图的改变而改变
UIViewAutoresizingFlexibleLeftMargin 自动调整view与父视图左边距,以保证右边距不变
UIViewAutoresizingFlexibleWidth 自动调整view的宽度,保证左边距和右边距不变
UIViewAutoresizingFlexibleRightMargin 自动调整view与父视图右边距,以保证左边距不变
UIViewAutoresizingFlexibleTopMargin 自动调整view与父视图上边距,以保证下边距不变
UIViewAutoresizingFlexibleHeight 自动调整view的高度,以保证上边距和下边距不变
UIViewAutoresizingFlexibleBottomMargin 自动调整view与父视图的下边距,以保证上边距不变
3. UIViewContentMode

Aspect : 按照图片的原来宽高比进行缩
UIViewContentModeScaleAspectFit : 按照图片的原来宽高比进行缩放(一定要看到整张图片)
UIViewContentModeScaleAspectFill : 按照图片的原来宽高比进行缩放(只能图片最中间的内容)
UIViewContentModeScaleToFill : 直接拉伸图片至填充整个imageView

4. 通过代码自定义Cell的步骤
    1.新建一个继承自UITableViewCell的类
    2.重写initWithStyle:reuseIdentifier:方法
        添加所有需要显示的子控件(不需要设置子控件的数据和frame,  子控件要添加到contentView中)
        进行子控件一次性的属性设置(有些属性只需要设置一次, 比如字体\固定的图片)
    3.提供2个模型
        数据模型: 存放文字数据\图片数据
        frame模型: 存放数据模型\所有子控件的frame\cell的高度
    4.cell拥有一个frame模型(不要直接拥有数据模型)
    5.重写frame模型属性的setter方法: 在这个方法中设置子控件的显示数据和frame
    6.frame模型数据的初始化已经采取懒加载的方式(每一个cell对应的frame模型数据只加载一次)
5. 重用Cell

Cell重用的目的,就是为了防止不断创建与销毁
如果不创建内存也不会增大,只是会快速的创建销毁

6. 当你碰到tableview cell里报nan错误时的解决方法

这种错误是在float经过函数运行出了不是数字的值,nan的意思就是not a number。
主要常见原因:

    1.除以0
    2.sizeWithFont的字符串为nil
    3.数学函数不正确运算

解决方法除了排除根源所在之外,用函数isnan()也是不错的选择(至少在没有彻底解决以前)

float _x = NAN;
if (!isnan(_x)) {
        cell.imgView.frame = CGRectMake(_x, 8, 10, 12);
}
7. 最底下的那个CELL没有分割线
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 1.创建cell
    MJSettingCell *cell = [MJSettingCell cellWithTableView:tableView];
    
    // 2.给cell传递模型数据
    MJSettingGroup *group = self.data[indexPath.section];
    cell.item = group.items[indexPath.row];
    cell.lastRowInSection =  (group.items.count - 1 == indexPath.row);
    
    // 3.返回cell
    return cell;
}

然后重写cell里面lastRowInSection的set方法

- (void)setLastRowInSection:(BOOL)lastRowInSection
{
    _lastRowInSection = lastRowInSection;
    
    self.divider.hidden = lastRowInSection;
}

你可能感兴趣的:(iOS笔记)