//
//  ViewController.m
//  Group
//
//  Created by randy on 16/3/1.
//  Copyright 漏 2016骞?Randy. All rights reserved.
//

#import "ViewController.h"
#import "LeftTableViewCell.h"
#import "RightCollectionViewCell.h"
@interface ViewController ()
@property (nonatomic, strong) UICollectionView *rightCollectionView;
@property (nonatomic ,strong) NSArray *dataArr;
@property (nonatomic ,strong) NSArray *myData;
@property (nonatomic ,assign) NSInteger selectedIndex;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"鍒嗙被";
    _dataArr = [[NSArray alloc]initWithObjects:@"鎺ㄨ崘鍒嗙被", @"娼祦濂宠",@"鍝佺墝鐢疯",@"閰掓按楗枡",@"瀹剁敤鐢靛櫒",@"鎵嬫満鏁扮爜",@"鐢佃剳鍔炲叕",@"鍥句功",@"灞呭鐢熸椿",@"杩愬姩鎴峰",@"鐜╁叿涔愬櫒",@"閽熻〃鐝犲疂",@"椋熷搧鐢熼矞",@"濂緢绀煎搧",@"姹借溅鐢ㄥ搧",@"鐢熸椿鏃呰",nil];
    _myData = [[NSArray alloc]initWithObjects:@"绗旇鏈?,@"浼戦棽瑁?,@"鐗涗粩瑁?,@"鎵嬫満",@"鍑€鍖栧櫒",@"鐏攨",@"OPPO",@"闈㈣啘",@"婕卞彛姘?,@"娴嬭瘯",@"娴嬭瘯1", nil];
    [self CreatRightCollectionView];
}
-(void)CreatRightCollectionView
{
    UICollectionViewFlowLayout *flowayout = [[UICollectionViewFlowLayout alloc]init];
    
    flowayout.minimumInteritemSpacing = 0.f;
    flowayout.minimumLineSpacing = 0.5f;
    
    _rightCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(100, 64, self.view.frame.size.width-100, self.view.frame.size.height) collectionViewLayout:flowayout];
    
    [_rightCollectionView registerClass:[RightCollectionViewCell class] forCellWithReuseIdentifier:@"RightCollectionViewCell"];
    
    [_rightCollectionView setBackgroundColor:[UIColor clearColor]];
    
    
    _rightCollectionView.delegate = self;
    _rightCollectionView.dataSource = self;
    
    [self.view addSubview:_rightCollectionView];


}
//瀹炵幇TableView鐨勪唬鐞嗘柟娉?
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return _dataArr.count;

}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (!cell)
    {
        NSArray *ArrayCell = [[NSBundle mainBundle]loadNibNamed:@"LeftTableViewCell" owner:self options:nil];
        cell = ArrayCell[0];
    }
    cell.tableview_textLabel.text = _dataArr[indexPath.row];
    
    cell.selectionStyle = 1;//璁剧疆Cell閫変腑鏁堟灉
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 44;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
   [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    
    [_rightCollectionView scrollRectToVisible:CGRectMake(0, 0, self.rightCollectionView.frame.size.width, self.rightCollectionView.frame.size.height) animated:YES];
    
    
    _selectedIndex = indexPath.row;
    
    [_rightCollectionView reloadData];

}

#pragma mark------CollectionView鐨勪唬鐞嗘柟娉?-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return _myData.count;

}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    RightCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RightCollectionViewCell" forIndexPath:indexPath];
    //鏍规嵁宸﹁竟鐐瑰嚮鐨刬ndepath鏇存柊鍙宠竟鍐呭;
    switch (_selectedIndex)
    {
        case 0:
            cell.collectionView_imageview.image = [UIImage imageNamed:@"3.jpg"];
            break;
        case 1:
            cell.collectionView_imageview.image = [UIImage imageNamed:@"4.jpg"];
            break;
        case 2:
            cell.collectionView_imageview.image = [UIImage imageNamed:@"3.jpg"];
            break;
        case 3:
            cell.collectionView_imageview.image = [UIImage imageNamed:@"4.jpg"];
            break;
        default:
            break;
    }
    
    cell.collectionView_Label.text = _myData[indexPath.row];
    
    return cell;
    

}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{

    return UIEdgeInsetsMake(0, 5, 0, 10);

}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(100, 120);


}
@end
// 鐗堟潈灞炰簬鍘熶綔鑰?// http://code4app.com (cn) http://code4app.net (en)
// 鍙戝竷浠g爜浜庢渶涓撲笟鐨勬簮鐮佸垎浜綉绔? Code4App.com