终于大致tableview知道如何刷新了


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *cellIdentifier = @"Cell";

    BDStoryShelfCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (!cell) {

        cell = [[BDStoryShelfCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

        cell.backgroundColor = [UIColor clearColor];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.delegate = self;

    }

    

    NSMutableArray *array = [[NSMutableArray alloc] init];

    


    NSInteger startIndex = indexPath.row * KeyStoryShelfBookCount;

    NSInteger step = KeyStoryShelfBookCount;

    

    for(int i = 0;i < step;i++) {

        

        NSInteger index = startIndex + i;

        

        if(index < self.bookListArray.count) {


            BDStoryBookDetailInfo *bookInfo = [self.bookListArray objectAtIndex:index];

            [array addObject:bookInfo];

        }

    }

    [cell refreshWithData:array];

    

    return cell;

}



//**********************************************************************************


#import "BDStoryBaseTableViewCell.h"

#import "BDStroyBookListModel.h"

#import "BDStoryBookDetailInfo.h"


#define KeyStoryShelfCellHeight   118


#define KeyStoryShelfBookCount  (BDIPHONE_SCREEN_WIDTH_PORT>320?4:3//书架中每行所放书的个数


@protocol BDStoryShelfCellDelegate <NSObject>

- (void)addBookButtonClicked;

@end


/**

 *  书架 cell

 */

@interface BDStoryShelfCell :BDStoryBaseTableViewCell


@property (nonatomic,assign) id<BDStoryShelfCellDelegate> delegate;


- (void)refreshWithData:(NSArray *)array;

@end







//--------------------------------------------------------------------------------------------------------------------------------------

#import "BDStoryShelfCell.h"

#import "BDStoryRelateSubCell.h"

#import "BDStoryShelfSubCell.h"

#import "BDStoryCommonModel.h"


#define KeySubCellOffY  12


#define KeyAddButtonWidth   62

#define KeyAddButtonHeight  86


#define KeySubCellLeft      20//图标距离左间距距离


#define KeySubCellGap       ((BDIPHONE_SCREEN_WIDTH_PORT-KeySubCellLeft*2-BDStoryShelfCellWidth*KeyStoryShelfBookCount)/(CGFloat)(KeyStoryShelfBookCount-1))//两图标之间的间距


@interface BDStoryShelfCell()

@property (nonatomic,strong) UIImageView          *bottomImageView;

@property (nonatomic,strong) UIButton             *addButton;//添加书架图标

@property (nonatomic,strong) NSMutableArray       *subCells;

@end


@implementation BDStoryShelfCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

    self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        

        if (!self.bottomImageView) {

            self.bottomImageView = [[UIImageViewalloc] init];

        }

        self.bottomImageView.backgroundColor = [UIColorclearColor];

        self.bottomImageView.frame =CGRectMake(0,KeyStoryShelfCellHeight-21,BDIPHONE_SCREEN_WIDTH_PORT, 21);

        self.bottomImageView.image = [UIImageimageNamed:@"bookshelf"];

        [selfaddSubview:self.bottomImageView];

        

        if (!self.addButton) {

            self.addButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

        }

        self.addButton.backgroundColor = [UIColorclearColor];

        [self.addButtonsetBackgroundImage:[UIImageimageNamed:@"add"]forState:UIControlStateNormal];

        [self.addButtonaddTarget:selfaction:@selector(addButtonClicked:)forControlEvents:UIControlEventTouchUpInside];

        self.addButton.hidden =YES;

        [selfaddSubview:self.addButton];

        

        self.subCells = [[NSMutableArrayalloc] init];

        for (int i =0; i < KeyStoryShelfBookCount; i++) {

            BDStoryShelfSubCell *subCell = [[BDStoryShelfSubCellalloc] init];

            subCell.backgroundColor = [UIColorredColor];

            subCell.frame =CGRectMake(KeySubCellLeft + (KeySubCellGap+BDStoryShelfCellWidth)*i,KeySubCellOffY, BDStoryShelfCellWidth,BDStoryShelfCellHeight);

            subCell.hidden =YES;

            [selfaddSubview:subCell];

            [self.subCellsaddObject:subCell];

        }

    }

    

    returnself;

}


/**

 * 刷新数据

 */

- (void)refreshWithData:(NSArray *)array

{

    

    for (int i =0; i < array.count; i++) {

        BDStoryShelfSubCell *subCell = [self.subCellsobjectAtIndex:i];

        subCell.hidden =NO;

        [subCell refreshWithData:[array objectAtIndex:i]];

    }

    

    if (array.count <self.subCells.count) {

        for (int i = (int)array.count; i < (int)self.subCells.count ; i++) {

            BDStoryShelfSubCell *subCell = [self.subCellsobjectAtIndex:i];

            subCell.hidden =YES;

        }

    }


    if (array.count  <KeyStoryShelfBookCount) {

        self.addButton.hidden =NO;

        self.addButton.frame =CGRectMake(KeySubCellLeft+(KeySubCellGap+BDStoryShelfCellWidth)*(array.count%KeyStoryShelfBookCount),KeySubCellOffY-KeyCoverImageOffSet,KeyAddButtonWidth, KeyAddButtonHeight);

    } else {

        self.addButton.hidden =YES;

    }

    

    return;

}


#pragma mark - Methods


- (void)addButtonClicked:(UIButton *)sender

{

    if (self.delegate && [self.delegaterespondsToSelector:@selector(addBookButtonClicked)]) {

        [self.delegateaddBookButtonClicked];

    }

}


@end




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值