Xcode_静态库制作_基础篇

2018-08-28  本文已影响13人  茉上心弦
选择 Cocoa Touch Static Library
/** 快速获取 cell */
+ (instancetype)cell:(UITableView*)tableView;

/** 快速获取 cell(Xib/故事版) */
+ (instancetype)resourceCell:(UITableView*)tableView;

在 BaseCell.m 文件中实现以上两个方法:

/** 快速获取 cell */
+ (instancetype)cell:(UITableView*)tableView {
    NSString* ID = NSStringFromClass(self);
    BaseCell* cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (!cell) {
        [tableView registerClass:self forCellReuseIdentifier:ID];
        cell = [tableView dequeueReusableCellWithIdentifier:ID];
    }
    
    return cell;
}

/** 快速获取 cell(Xib/故事版) */
+ (instancetype)resourceCell:(UITableView*)tableView {
    NSString* ID = NSStringFromClass(self);
    BaseCell* cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (!cell) {
        [tableView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellReuseIdentifier:ID];
        cell = [tableView dequeueReusableCellWithIdentifier:ID];
    }
    
    return cell;
}

两个子目录,就是编译结果。分别进入字目录中,会发现有这样的文件libBaseCell.a,这就是一个静态库了,但是模拟器于真机的是分开的。在开发中,往往是需要合并的。


会发现在 Products 目录中多了一个 libBaseCell1.a 文件。这个文件就是模拟器于真机合并的静态库,在开发的过程中,往往都是用这个合并库。



上一篇 下一篇

猜你喜欢

热点阅读