PopoverViewController.m 3.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
//
//  PopoverViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/9.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "PopoverViewController.h"

@interface PopoverViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *popoverTableView;

@end

@implementation PopoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
}


#pragma mark -UI
- (void)uiConfigAction
{
    self.popoverTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.contentSize.width, self.contentSize.height) style:UITableViewStylePlain];
    self.popoverTableView.dataSource = self;
    self.popoverTableView.delegate = self;
勾芒's avatar
勾芒 committed
32
    self.popoverTableView.showsVerticalScrollIndicator = NO;
33 34
    self.popoverTableView.tableFooterView = [UIView new];
    [self.view addSubview:self.popoverTableView];
勾芒's avatar
勾芒 committed
35
//    self.popoverTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
36 37 38 39
    [self.popoverTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"popovercell"];
}


勾芒's avatar
勾芒 committed
40 41 42 43 44 45 46 47
#pragma mark -填充数据
- (void)setDatasArray:(NSArray *)datasArray
{
    _datasArray = datasArray;
    [self.popoverTableView reloadData];
}


48 49 50 51
#pragma mark - UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"popovercell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
52 53 54 55 56 57
    
    //显示纯图片
    if (self.isPictures) {
        cell.imageView.image = TCImage([self.datasArray objectAtIndex_opple:indexPath.row]);
        return cell;
    }
勾芒's avatar
勾芒 committed
58 59 60 61
    if (self.isString) {
        cell.textLabel.text = [self.datasArray objectAtIndex_opple:indexPath.row];
    }else
    {
62
       cell.textLabel.text = [[self.datasArray objectAtIndex_opple:indexPath.row] typeName];
勾芒's avatar
勾芒 committed
63
    }
64
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
勾芒's avatar
勾芒 committed
65
    cell.textLabel.font = [UIFont systemFontOfSize:14];
66 67 68 69 70 71 72 73 74 75 76 77
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datasArray.count;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
78
    WS(weakSelf);
勾芒's avatar
勾芒 committed
79 80 81
    if (self.isPictures)
    {
        if ([self.delegate respondsToSelector:@selector(returnWithIndexSelected:)]) {
82 83
            [self dismissViewControllerAnimated:YES completion:nil];
            [weakSelf.delegate returnWithIndexSelected:indexPath.row];
勾芒's avatar
勾芒 committed
84 85 86 87
        }
    }else
    {
        if ([self.delegate respondsToSelector:@selector(returnCellindexpathwithrow:WithcellTitle:Withselected:)]) {
88
            [self dismissViewControllerAnimated:YES completion:nil];
勾芒's avatar
勾芒 committed
89
            //判断是为纯字符串选中
90 91 92 93
            if (weakSelf.isString) {
                [weakSelf.delegate returnCellindexpathwithrow:[weakSelf.datasArray objectAtIndex_opple:indexPath.row] WithcellTitle:[weakSelf.datasArray objectAtIndex_opple:indexPath.row] Withselected:_Selectedindex];
            }else{
                [weakSelf.delegate returnCellindexpathwithrow:[[weakSelf.datasArray objectAtIndex_opple:indexPath.row] typecode] WithcellTitle:[[weakSelf.datasArray objectAtIndex_opple:indexPath.row] typeName] Withselected:_Selectedindex];
勾芒's avatar
勾芒 committed
94
            }
勾芒's avatar
勾芒 committed
95 96 97 98 99 100 101
        }
    }    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
勾芒's avatar
勾芒 committed
102
    return 44;
103 104 105 106 107 108 109 110 111 112
}


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


@end