zoukankan      html  css  js  c++  java
  • ios 有很多种cell时的写法 以及 masonry 的使用

      1  
    //当有很多种cell时的写法
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 2 { 3 return [self.theDataSource getCellHeightByPath:indexPath]; 4 } 5 -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 6 { 7 8 NSString *reuseid = [self.theDataSource getReuseIdentityByPath:indexPath]; 9 BSBaseTableCell* cell = (BSBaseTableCell*)[tableView dequeueReusableCellWithIdentifier:reuseid]; 10 if (!cell) { 11 Class cls = [self.theDataSource getCellClassByPath:indexPath]; 12 cell = [[cls alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseid]; 13 14 if ([cell isKindOfClass:[BSBaseTableCell class]]) 15 { 16 cell.delegate = self.cellDelegate; 17 } 18 19 } 20 BSLog(@"%@", NSStringFromClass(cell.class)); 21 BSBaseCellData* data = [self.theDataSource getDataByIndexPath:indexPath]; 22 23 if ([cell isKindOfClass:[BSBaseTableCell class]]) { 24 if (self.theDataSource.isInSelectingMode) { 25 26 WSO(wss, cell) 27 [UIView animateWithDuration:0.2 animations:^{ 28 [cell.contentView mas_remakeConstraints:^(MASConstraintMaker *make) { 29 make.left.top.bottom.equalTo(wss); 30 make.right.equalTo(wss.mas_right).offset(-36); 31 }]; 32 [self layoutIfNeeded]; 33 } completion:^(BOOL finished) { 34 cell.selectedForEdit = data.selectedForEdit; 35 [UIView animateWithDuration:0.1 animations:^{ 36 [cell.selectView mas_remakeConstraints:^(MASConstraintMaker *make) { 37 make.size.mas_equalTo(CGSizeMake(20, 20)); 38 make.top.equalTo(wss).offset(20); 39 make.right.equalTo(wss.mas_right).offset(-15); 40 }]; 41 [self layoutIfNeeded]; 42 }]; 43 }]; 44 45 cell.isInSelectingMode = YES; 46 } 47 else 48 { 49 if (cell.isInSelectingMode) { 50 WSO(wss, cell) 51 [UIView animateWithDuration:0.2 animations:^{ 52 [cell.contentView mas_remakeConstraints:^(MASConstraintMaker *make) { 53 make.left.right.top.bottom.equalTo(wss); 54 }]; 55 [self layoutIfNeeded]; 56 }]; 57 [cell.selectView mas_remakeConstraints:^(MASConstraintMaker *make) { 58 make.size.mas_equalTo(CGSizeMake(20, 20)); 59 make.top.equalTo(wss).offset(20); 60 make.right.equalTo(wss.mas_right).offset(20); 61 }]; 62 } 63 cell.isInSelectingMode = NO; 64 65 } 66 67 68 if ([cell respondsToSelector:@selector(setData:)]) { 69 [cell setData:data]; 70 } 71 if ([data isKindOfClass:[BSBaseCellData class]]) { 72 cell.accessoryType = data.cellAccessoryType; 73 } 74 75 } 76 else 77 { 78 if ([cell respondsToSelector:@selector(setCellData:)]) { 79 [cell setCellData:data]; 80 } 81 82 } 83 if ([cell respondsToSelector:@selector(setSeparatorLineVisible:)] && [data isKindOfClass:[BSBaseCellData class]]) { 84 [cell setSeparatorLineVisible:!data.isHideLine]; 85 } 86 return cell; 87 } 88
    //autolayout 使用
    90 91 WS(ws); 92 // [lab mas_makeConstraints:^(MASConstraintMaker *make) { 93 // make.centerY.equalTo(ws); 94 // make.left.equalTo(ws.mas_left).offset(BookRoomView_LeftSpace); 95 // }]; 96 // 97 // [style mas_makeConstraints:^(MASConstraintMaker *make) { 98 // make.left.equalTo(lab.mas_right).offset(6); 99 // make.centerY.equalTo(ws); 100 // }]; 101 // [label mas_makeConstraints:^(MASConstraintMaker *make) { 102 // make.right.equalTo(ws.mas_right).offset(-100); 103 // make.centerY.equalTo(ws.mas_centerY); 104 // }]; 105 // [zuopin mas_makeConstraints:^(MASConstraintMaker *make) { 106 // make.left.equalTo(label.mas_right).offset(6); 107 // make.centerY.equalTo(ws.mas_centerY); 108 // }]; 109 这个是masonry适配的代码,用的时候要记得WS(ws) he WS(wso,object)应为block避免循环应用,我这个没加

     更多详细介绍:http://www.cocoachina.com/ios/20141219/10702.html

  • 相关阅读:
    钱多多软件制作04
    团队项目01应用场景
    HDU 4411 arrest
    HDU 4406 GPA
    HDU 3315 My Brute
    HDU 3667 Transportation
    HDU 2676 Matrix
    欧拉回路三水题 POJ 1041 POJ 2230 POJ 1386
    SPOJ 371 BOXES
    POJ 3422 Kaka's Matrix Travels
  • 原文地址:https://www.cnblogs.com/song-kl/p/4631341.html
Copyright © 2011-2022 走看看