HomeViewController.m 12.7 KB
Newer Older
admin's avatar
admin committed
1 2 3 4 5 6 7 8 9 10 11
//
//  HomeViewController.m
//  redstar
//
//  Created by admin on 15/10/23.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeHeaderView.h"
#import "HomeFunctionCell.h"
12
#import "NewAnnounceCell.h"
admin's avatar
admin committed
13 14 15

#import "InspectListViewController.h"
#import "RankingListViewController.h"
16 17 18
#import "OnLineViewController.h"
#import "PictureViewController.h"
#import "QuestionViewController.h"
admin's avatar
admin committed
19

20
#define kNewAnnounceCell @"NewAnnounceTableViewCell"
admin's avatar
admin committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#define kHomeFunctionCell @"HomeFunctionCell"

@interface HomeViewController () <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
// 当前视图
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) HomeHeaderView *headView;

@property (nonatomic, strong) NSArray *titleArray; // section标题
@property (nonatomic, strong) NSArray *announeArray; // 公告内容
@end

@implementation HomeViewController
#pragma mark - ViewDidLoad
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"首页"];
    customLab.font = [UIFont boldSystemFontOfSize:19];
    self.navigationItem.titleView = customLab;
    
    // 初始化容器
    self.titleArray = [NSArray arrayWithObjects:@"最新公告", @"常用功能", nil];
    self.announeArray = [NSArray arrayWithObjects:@"关于展开10月口碑巡检的说明", @"迎2015十一大促活动启动", @"9月口碑巡检结果排名已公布", nil];
    
    [self setupTableView];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Private Methods
- (void)setupTableView
{
    self.headView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 125)];
    self.tableView.tableHeaderView = self.headView;
}

- (void)moreButtonClick:(UIButton *)sender
{
    NSLog(@"查看全部公告···");
}

75
// 在线抽查或任务处理
admin's avatar
admin committed
76 77
- (void)onLineSamplingClick:(UIButton *)sender
{
78 79 80
    OnLineViewController *onLineVC = [[OnLineViewController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:onLineVC animated:YES];
admin's avatar
admin committed
81 82
}

83
// 口碑列表 或口碑排名
admin's avatar
admin committed
84 85
- (void)wordOfMouthClick:(UIButton *)sender
{
86
    InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
admin's avatar
admin committed
87
    self.hidesBottomBarWhenPushed = YES;
88 89 90 91 92
    [self.navigationController pushViewController:inspectListVC animated:YES];
    
//    RankingListViewController *rankListVC = [[RankingListViewController alloc] init];
//    self.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:rankListVC animated:YES];
admin's avatar
admin committed
93 94
}

95
// 问题与知识
admin's avatar
admin committed
96 97
- (void)questionClick:(UIButton *)sender
{
98 99 100
    QuestionViewController *questionVC = [[QuestionViewController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:questionVC animated:YES];
admin's avatar
admin committed
101 102 103 104 105 106 107
}

- (void)standardClick:(UIButton *)sender
{
    
}

108
// 图说口碑
admin's avatar
admin committed
109 110
- (void)pictureClick:(UIButton *)sender
{
111 112 113
    PictureViewController *pictureVC = [[PictureViewController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:pictureVC animated:YES];
admin's avatar
admin committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
}

- (void)caseClick:(UIButton *)sender
{
    
}




#pragma mark - TableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _titleArray.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 3;
    } else {
        return 1;
    }
}

// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
144
        NewAnnounceCell *cell=[tableView dequeueReusableCellWithIdentifier:kNewAnnounceCell];
admin's avatar
admin committed
145
        if (!cell) {
146
            cell = [[NewAnnounceCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kNewAnnounceCell];
admin's avatar
admin committed
147
        }
148
        cell.announceLabel.text = _announeArray[indexPath.row];
admin's avatar
admin committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    } else {
        HomeFunctionCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeFunctionCell];
        if (!cell) {
            cell = [[HomeFunctionCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeFunctionCell];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.onLineSamplingBtn addTarget:self action:@selector(onLineSamplingClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.wordOfMouthBtn addTarget:self action:@selector(wordOfMouthClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.questionBtn addTarget:self action:@selector(questionClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.standardBtn addTarget:self action:@selector(standardClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.pictureBtn addTarget:self action:@selector(pictureClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.caseBtn addTarget:self action:@selector(caseClick:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
    
}

// cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 40;
    } else {
        return 240;
    }
}

// section高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 36;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}

// 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    // 创建sectionView
    UIView *sectionView = [[UIView alloc] init];
    sectionView.userInteractionEnabled = YES;
    sectionView.backgroundColor = kSectionBackGroundColor;
    // 创建标题label
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
    titleLabel.textColor = kHomeSectionTitleTextColor;
    titleLabel.font = [UIFont systemFontOfSize:17.0];
    titleLabel.text = _titleArray[section];
    [sectionView addSubview:titleLabel];
    
    NSLayoutConstraint *titleLabelTop = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:3];
    [sectionView addConstraint:titleLabelTop];
    
    NSLayoutConstraint *titleLabelLeft = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
    [sectionView addConstraint:titleLabelLeft];
    
    NSLayoutConstraint *titleLabelWidth = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:80];
    [sectionView addConstraint:titleLabelWidth];
    
    NSLayoutConstraint *titleLabelBottom = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
    [sectionView addConstraint:titleLabelBottom];
    
    
    if (section == 0) {
         // 查看更多按钮
        UIButton *moreButton = [[UIButton alloc] init];
        moreButton.translatesAutoresizingMaskIntoConstraints = NO;
        [moreButton setTitle:@"查看全部" forState:UIControlStateNormal];
        [moreButton setTitleColor:kMoreButtonTextColor forState:UIControlStateNormal];
        [moreButton addTarget:self action:@selector(moreButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        moreButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
        [sectionView addSubview:moreButton];
        
        // 箭头Iamge
        UIImageView *arrowIamgeView = [[UIImageView alloc] init];
230
        arrowIamgeView.image = [UIImage imageNamed:@"arrow_right"];
admin's avatar
admin committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
        arrowIamgeView.translatesAutoresizingMaskIntoConstraints = NO;
        [sectionView addSubview:arrowIamgeView];
        
        // moreButton布局
        NSLayoutConstraint *moreButtonTop = [NSLayoutConstraint constraintWithItem:moreButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:3];
        [sectionView addConstraint:moreButtonTop];
        
        NSLayoutConstraint *moreButtonRight = [NSLayoutConstraint constraintWithItem:moreButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:arrowIamgeView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [sectionView addConstraint:moreButtonRight];
        
        NSLayoutConstraint *moreButtonWidth = [NSLayoutConstraint constraintWithItem:moreButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:60];
        [sectionView addConstraint:moreButtonWidth];
        
        NSLayoutConstraint *moreButtonBottom = [NSLayoutConstraint constraintWithItem:moreButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [sectionView addConstraint:moreButtonBottom];
        
        // arrowIamgeView布局
248
        NSLayoutConstraint *arrowIamgeViewTop = [NSLayoutConstraint constraintWithItem:arrowIamgeView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:13];
admin's avatar
admin committed
249 250
        [sectionView addConstraint:arrowIamgeViewTop];
        
251
        NSLayoutConstraint *arrowIamgeViewRight = [NSLayoutConstraint constraintWithItem:arrowIamgeView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
admin's avatar
admin committed
252 253
        [sectionView addConstraint:arrowIamgeViewRight];
        
254
        NSLayoutConstraint *arrowIamgeViewWidth = [NSLayoutConstraint constraintWithItem:arrowIamgeView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:7];
admin's avatar
admin committed
255 256
        [sectionView addConstraint:arrowIamgeViewWidth];
        
257
        NSLayoutConstraint *arrowIamgeViewHeight = [NSLayoutConstraint constraintWithItem:arrowIamgeView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:12];
admin's avatar
admin committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
        [sectionView addConstraint:arrowIamgeViewHeight];
    } else {
        
    }
    
    return sectionView;
}

#pragma mark - lazy loading
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.translatesAutoresizingMaskIntoConstraints = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
276
        [_tableView registerClass:[NewAnnounceCell class] forCellReuseIdentifier:kNewAnnounceCell];
admin's avatar
admin committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
        [_tableView registerClass:[HomeFunctionCell class] forCellReuseIdentifier:kHomeFunctionCell];
        [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