//
//  ViewController.m
//  MHActionSheet
//
//  Created by hcl on 16/3/10.
//  Copyright 漏 2016骞?hcl. All rights reserved.
//

#import "ViewController.h"
#import "MHActionSheet.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *dataSource;
@property (strong, nonatomic) NSMutableArray *selectSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.tableFooterView = [UIView new];
    [self loadDataSource];
}

- (void)loadDataSource
{
    self.dataSource = [NSMutableArray new];
    [_dataSource addObject:@"鏅€氭ā寮?];
    [_dataSource addObject:@"鍙樿壊鍙樺瓧妯″紡"];
    [_dataSource addObject:@"琛屾暟瓒呭妯″紡"];
    [_dataSource addObject:@"WeiChat妯″紡"];
    [_dataSource addObject:@"WeiChat澶氳妯″紡"];
    [_dataSource addObject:@"TableView妯″紡"];
    
    self.selectSource = [NSMutableArray new];
    
    for (int i = 0; i < self.dataSource.count; i++) {
        [_selectSource addObject:@""];
    }
}

#pragma mark - UITableView鏁版嵁婧愬拰浠g悊鏂规硶
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"cell";
    UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.font = [UIFont systemFontOfSize:20.0];
    cell.textLabel.text = _dataSource[indexPath.row];
    cell.detailTextLabel.text = _selectSource[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 閫変腑鍚庣珛鍗冲彇娑堥€変腑鐘舵€?    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    switch (indexPath.row) {
        case 0:
        {
            MHActionSheet *actionSheet = [[MHActionSheet alloc] initSheetWithTitle:nil style:MHSheetStyleDefault itemTitles:@[@"澶寸瓑鑸?,@"鍟嗗姟鑸?,@"缁忔祹鑸?,@"涓嶉檺"]];
            __weak typeof(self) weakSelf = self;
            [actionSheet didFinishSelectIndex:^(NSInteger index, NSString *title) {
                NSString *text = [NSString stringWithFormat:@"绗?ld琛?%@",index, title];
                [weakSelf.selectSource replaceObjectAtIndex:indexPath.row withObject:text];
                [weakSelf.tableView reloadData];
            }];
            
        }
            break;
        case 1:
        {
            MHActionSheet *actionSheet = [[MHActionSheet alloc] initSheetWithTitle:@"閫夋嫨鑸变綅" style:MHSheetStyleDefault itemTitles:@[@"澶寸瓑鑸?,@"鍟嗗姟鑸?,@"缁忔祹鑸?,@"涓嶉檺"]];
            actionSheet.titleTextFont = [UIFont systemFontOfSize:15];
            actionSheet.itemTextFont = [UIFont systemFontOfSize:18];
            actionSheet.cancleTextFont = [UIFont systemFontOfSize:16];
            actionSheet.titleTextColor = [UIColor redColor];
            actionSheet.itemTextColor = [UIColor orangeColor];
            actionSheet.cancleTextColor = [UIColor blackColor];
            __weak typeof(self) weakSelf = self;
            [actionSheet didFinishSelectIndex:^(NSInteger index, NSString *title) {
                NSString *text = [NSString stringWithFormat:@"绗?ld琛?%@",index, title];
                [weakSelf.selectSource replaceObjectAtIndex:indexPath.row withObject:text];
                [weakSelf.tableView reloadData];
            }];
        }
            break;
        case 2:
        {
            MHActionSheet *actionSheet = [[MHActionSheet alloc] initSheetWithTitle:@"甯骇閫夋嫨" style:MHSheetStyleDefault itemTitles:@[@"澶寸瓑鑸?,@"鍟嗗姟鑸?,@"缁忔祹鑸?,@"鐗圭瓑搴?,@"涓€绛夊骇",@"浜岀瓑搴?,@"杞骇",@"纭骇",@"澶寸瓑鑸?,@"鍟嗗姟鑸?,@"缁忔祹鑸?,@"鐗圭瓑搴?,@"涓€绛夊骇",@"浜岀瓑搴?,@"杞骇",@"纭骇",@"涓嶉檺"]];
            __weak typeof(self) weakSelf = self;
            [actionSheet didFinishSelectIndex:^(NSInteger index, NSString *title) {
                NSString *text = [NSString stringWithFormat:@"绗?ld琛?%@",index, title];
                [weakSelf.selectSource replaceObjectAtIndex:indexPath.row withObject:text];
                [weakSelf.tableView reloadData];
            }];
        }
            break;
        case 3:
        {
            MHActionSheet *actionSheet = [[MHActionSheet alloc] initSheetWithTitle:nil style:MHSheetStyleWeiChat itemTitles:@[@"澶寸瓑鑸?,@"鍟嗗姟鑸?,@"缁忔祹鑸?,@"涓嶉檺"]];
            __weak typeof(self) weakSelf = self;
            [actionSheet didFinishSelectIndex:^(NSInteger index, NSString *title) {
                NSString *text = [NSString stringWithFormat:@"绗?ld琛?%@",index, title];
                [weakSelf.selectSource replaceObjectAtIndex:indexPath.row withObject:text];
                [weakSelf.tableView reloadData];
            }];
        }
            break;
        case 4:
        {
            MHActionSheet *actionSheet = [[MHActionSheet alloc] initSheetWithTitle:@"甯骇閫夋嫨" style:MHSheetStyleWeiChat itemTitles:@[@"澶寸瓑鑸?,@"鍟嗗姟鑸?,@"缁忔祹鑸?,@"鐗圭瓑搴?,@"涓€绛夊骇",@"浜岀瓑搴?,@"杞骇",@"纭骇",@"澶寸瓑鑸?,@"鍟嗗姟鑸?,@"缁忔祹鑸?,@"鐗圭瓑搴?,@"涓€绛夊骇",@"浜岀瓑搴?,@"杞骇",@"纭骇",@"涓嶉檺"]];
            actionSheet.cancleTitle = @"鍙栨秷閫夋嫨";
            __weak typeof(self) weakSelf = self;
            [actionSheet didFinishSelectIndex:^(NSInteger index, NSString *title) {
                NSString *text = [NSString stringWithFormat:@"绗?ld琛?%@",index, title];
                [weakSelf.selectSource replaceObjectAtIndex:indexPath.row withObject:text];
                [weakSelf.tableView reloadData];
            }];
        }
            break;
        case 5:
        {
            MHActionSheet *actionSheet = [[MHActionSheet alloc] initSheetWithTitle:@"鏃堕棿閫夋嫨" style:MHSheetStyleTable itemTitles:@[@"10:00",@"11:00",@"12:00",@"13:00",@"14:00",@"15:00",@"16:00",@"17:00",@"18:00",@"19:00",@"20:00",@"21:00",@"22:00",@"23:00",@"23:59"]];
            __weak typeof(self) weakSelf = self;
            [actionSheet didFinishSelectIndex:^(NSInteger index, NSString *title) {
                NSString *text = [NSString stringWithFormat:@"绗?ld琛?%@",index, title];
                [weakSelf.selectSource replaceObjectAtIndex:indexPath.row withObject:text];
                [weakSelf.tableView reloadData];
            }];
        }
            break;
            
        default:
            break;
    }
}

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