美文网首页
iOS 常用到的知识点(二)

iOS 常用到的知识点(二)

作者: Dxc_iOS | 来源:发表于2018-12-20 17:57 被阅读5次

    iOS 常用到的知识点(一)
    iOS 常用到的知识点(二)
    iOS 常用到的知识点(三)

    1.延迟加载:

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * 
    NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        [self.tableView reloadData];
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.tableView footerEndRefreshing];
    });
    

    2.布尔值存本地:需要先转换成NSNumber,再存本地

      NSNumber * boolNum = [NSNumber numberWithBool:YES];
    BOOL  isOn = [boolNum boolValue];
    

    3. CGRectGetMaxY, CGRectGetMaxY等相关的使用

    CGRectGetHeight返回label本身的高度
    
     CGRectGetMinY返回label顶部的坐标
    
     CGRectGetMaxY 返回label底部的坐标
    
     CGRectGetMinX 返回label左边缘的坐标
    
     CGRectGetMaxX 返回label右边缘的坐标
    
     CGRectGetMidX表示得到一个frame中心点的X坐标
    
     CGRectGetMidY表示得到一个frame中心点的Y坐标
    

    4.UIButton的 UIEdgeInsets使用

    top : 为正数的时候,是往下偏移,为负数的时候往上偏移;
    left : 为正数的时候往右偏移,为负数的时候往左偏移;
    bottom : 为正数的时候往上偏移,为负数的时候往下偏移;
    right :为正数的时候往左偏移,为负数的时候往右偏移;
    

    5.UITableViewCell:隐藏删除按钮和设置删除按钮的标题(图片 或中文)

    - (void)viewDidLoad {
    [super viewDidLoad];
    self.editButtonItem.title = @"编辑";
    self.navigationItem.leftBarButtonItem = self.editButtonItem;
    }
    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    if (self.editing) {
    self.editButtonItem.title = @"完成";
    } else {
    self.editButtonItem.title = @"编辑";
    }
    }
    

    6.Masonry基础API:

    mas_makeConstraints()    添加约束
    mas_remakeConstraints()  移除之前的约束,重新添加新的约束
    mas_updateConstraints()  更新约束
            
    equalTo()       参数是对象类型,一般是视图对象或者mas_width这样的坐标系对象
    mas_equalTo()   和上面功能相同,参数可以传递基础数据类型对象,可以理解为比上面的API更强大
    width()         用来表示宽度,例如代表view的宽度
    mas_width()     用来获取宽度的值。和上面的区别在于,一个代表某个坐标系对象,一个用来获取坐标系对象的值
    

    7.刷新 section 和 cell

    //一个section刷新
    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
    [tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
    //一个cell刷新
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    

    7、根据cell中的view(类)创建indexPath

    UIView *view = [button superview];
    UITableViewCell *selCell2 = (UITableViewCell *)[view superview];
    NSIndexPath *indexPath = [self.tableView indexPathForCell:selCell2];
    NSLog(@"indexPath is2 = %ld",indexPath.row);
    

    相关文章

      网友评论

          本文标题:iOS 常用到的知识点(二)

          本文链接:https://www.haomeiwen.com/subject/vwtukqtx.html