// // SelectCategaryViewController.m // redstar // // Created by admin on 16/6/6. // Copyright © 2016年 ZWF. All rights reserved. // #import "SelectCategaryViewController.h" @interface SelectCategaryViewController () <UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @end @implementation SelectCategaryViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setupNav]; self.tableView.backgroundColor = [UIColor whiteColor]; self.view.backgroundColor = [UIColor whiteColor]; } - (void)setupNav { UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)]; [customLab setTextColor:[UIColor whiteColor]]; [customLab setText:[NSString stringWithFormat:@"选择%@", self.titleStr]]; customLab.font = [UIFont boldSystemFontOfSize:19]; self.navigationItem.titleView = customLab; UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; backBtn.frame = CGRectMake(0, 0, 30, 44); [backBtn setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal]; [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn]; self.navigationItem.leftBarButtonItem = backItem; } - (void)doBack:(id)sender { [self.navigationController popViewControllerAnimated:YES]; } #pragma mark - UItableView Delegate/DataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _titleArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"selectCategoryCell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"selectCategoryCell"]; } cell.textLabel.text = _titleArray[indexPath.row]; return cell; } // cell点击事件 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([_delegate respondsToSelector:@selector(selectCategaryWithIndexPath:rowNum:)]) { [_delegate selectCategaryWithIndexPath:indexPath rowNum:self.rowNum]; } [self.navigationController popViewControllerAnimated:YES]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectZero]; _tableView.translatesAutoresizingMaskIntoConstraints = NO; _tableView.delegate = self; _tableView.dataSource = self; _tableView.showsVerticalScrollIndicator = NO; _tableView.showsHorizontalScrollIndicator = NO; _tableView.tableFooterView = [[UIView alloc] init]; [self.view addSubview:_tableView]; NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]; [self.view addConstraint:tableTop]; NSLayoutConstraint *tableLeft = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]; [self.view addConstraint:tableLeft]; NSLayoutConstraint *tableRight = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]; [self.view addConstraint:tableRight]; NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]; [self.view addConstraint:tableBottom]; } return _tableView; } @end