瀑布流接口的设计以及应用(五)

//
//  ViewController.h
//  瀑布流
//
//  Created by Jose on 15-7-11.
//  Copyright (c) 2015年 Jose. All rights reserved.
//


#import <UIKit/UIKit.h>
@interface ViewController : UIViewController


@end



*************************************************************************************************************

************************************************************************************************************

************************************************************************************************************

//
//  ViewController.m
//  瀑布流
//
//  Created by Jose on 15-7-11.
//  Copyright (c) 2015年 Jose. All rights reserved.
//


#import "ViewController.h"
#import "MyWaterFlowView.h"
#import "MyWaterFlowViewCell.h"
#import "MyShop.h"
#import "MJExtension.h"
#import "MyShopCell.h"
#import "MJRefresh.h"


@interface ViewController ()<MyWaterFlowViewDataSource,MyWaterFlowViewDelegate>
/** 用于存放*/
@property(nonatomic,strong)NSMutableArray *shops;
@property(nonatomic,weak)MyWaterFlowView *mywaterflowviews;
@end


@implementation ViewController




-(NSMutableArray *)shops{
    if (_shops==nil) {
        self.shops=[NSMutableArray array];
    }
    return _shops;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化数据
    NSArray *newshops=[MyShop objectArrayWithFilename:@"2.plist"];
    [self.shops addObjectsFromArray:newshops];
    
    //瀑布流控间
    MyWaterFlowView *mywaterflowview=[[MyWaterFlowView alloc]init];
    //随者父控件的尺寸而自动伸缩
    mywaterflowview.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    mywaterflowview.frame=self.view.bounds;
    mywaterflowview.MyDataSource=self;
    mywaterflowview.MyDelegate=self;
    [self.view addSubview:mywaterflowview];
    self.mywaterflowviews=mywaterflowview;
    
    //刷新瀑布流中的数据
    //[mywaterflowview ReloadData];
    [mywaterflowview addHeaderWithTarget:self action:@selector(LoadNewShops)];
    [mywaterflowview addFooterWithTarget:self action:@selector(LoadMoreshops)];
    //[mywaterflowview addHeaderWithCallback:^{}];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//旋转屏幕刷新数据
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [self.mywaterflowviews ReloadData];
}


-(void)LoadNewShops{
    /***
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSArray *newshops=[MyShop objectArrayWithFile:@"1.plist"];
        [self.shops insertObjects:newshops atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, newshops.count)]];
    });
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0*NSEC_PER_SEC)), dispatch_get_main_queue(),^{
        [self.mywaterflowviews ReloadData];
        [self.mywaterflowviews headerEndRefreshing];
    });
     
     **/
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        // 加载1.plist
        NSArray *newShops = [MyShop objectArrayWithFilename:@"1.plist"];
        [self.shops insertObjects:newShops atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, newShops.count)]];
    });
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新瀑布流控件
        [self.mywaterflowviews ReloadData];
        
        // 停止刷新
        [self.mywaterflowviews headerEndRefreshing];
    });


}
-(void)LoadMoreshops{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSArray *moreshops=[MyShop objectArrayWithFilename:@"3.plist"];
        [self.shops addObjectsFromArray:moreshops];
    });
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.mywaterflowviews ReloadData];
        [self.mywaterflowviews footerEndRefreshing];
    });
}
#pragma mark 数据源方法
-(NSUInteger)NumberOfCellInWaterFlowView:(MyWaterFlowView *)mywaterflowview{
    return self.shops.count;
}


-(NSUInteger)NumberOfColumsInWaterFlowView:(MyWaterFlowView *)mywateflowview{
    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
        return 3;
    }
    else{
        return 5;
    }
}
-(MyWaterFlowViewCell *)WaterFlowViewCell:(MyWaterFlowView *)mywaterflowview CellAtIndex:(NSUInteger)index{
    
    MyShopCell *cell=[MyShopCell cellWithWaterFlowView:mywaterflowview];
    cell.shop=self.shops[index];
    //cell.backgroundColor=[UIColor orangeColor];
    return cell;
    
}




#pragma mark 代理方法
-(CGFloat)MyWaterFlowView:(MyWaterFlowView *)mywaterflowview HeightAtIndex:(NSUInteger)index{
    MyShop *shop=self.shops[index];
    //根据图片的宽高比返回cell的宽度
    return mywaterflowview.cellWidth*shop.h/shop.w;
   }


/***
-(CGFloat)MyWaterFlowView:(MyWaterFlowView *)mywaterflowview MarginType:(MyWaterFlowViewMarginType)type{
    switch (type) {
        case MyWaterFlowViewMarginTypeTop:
        case MyWaterFlowViewMarginTypeBottom:
        case MyWaterFlowViewMarginTypeLeft:
        case MyWaterFlowViewMarginTypeRight:
        case MyWaterFlowViewMarginTypeColumn:
        case MyWaterFlowViewMarginTypeRow:
            return 10;
            break;
        default:
            return 5;
            break;
    }
}


-(void)MyWaterFlowView:(MyWaterFlowView *)mywaterflowview DidSelectAtIndex:(NSUInteger)index{
    NSLog(@"点击了第几个%luindex",index);
}
***/
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值