做一個樓盤動態(tài)的table view,我主要是建model和寫tableview的delegate和datasource。
model
model用mantle來搭建,公司里的響應(yīng)數(shù)據(jù)主要是JSON,用mantle可以把JSON解析成數(shù)組,并且可以解析成數(shù)組中的數(shù)組。
@implementation LJNewHouseSeenRecordResponseModel
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"seenRecordData" : @"list"
};
}
+ (NSValueTransformer *)seenRecordDataJSONTransformer {
return [MTLJSONAdapter arrayTransformerWithModelClass:[LJNewHouseSeenRecordDataModel class]];
}
@end
上面的代碼中,seenRecordData也是一個數(shù)組,用同樣的方法做解析。
table view
網(wǎng)絡(luò)請求
網(wǎng)絡(luò)請求實際上是用的AFNetworking,公司在庫的基礎(chǔ)上做了一層封裝。由于要求是先出3條動態(tài),點擊查看更多以后再出三條,所以在網(wǎng)絡(luò)請求時要加上startIndex。
AutoLayout
AutoLayout是用masonry實現(xiàn),用法很簡單。
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top);
make.leading.equalTo(self.view.mas_leading);
make.bottom.equalTo(self.view.mas_bottom).with.offset(-49);
make.trailing.equalTo(self.view.mas_trailing);
}];
heightForRowAtIndexPath
由于設(shè)計中cell是不定高的,所以要在cell的model里寫一個計算cell高度的方法。