148 lines
4.8 KiB
Objective-C
148 lines
4.8 KiB
Objective-C
//
|
|
// TLSettingViewController.m
|
|
// TLChat
|
|
//
|
|
// Created by 李伯坤 on 16/2/7.
|
|
// Copyright © 2016年 李伯坤. All rights reserved.
|
|
//
|
|
|
|
#import "TLSettingViewController.h"
|
|
#import <MobClick.h>
|
|
#import "TLSettingHeaderTitleView.h"
|
|
#import "TLSettingFooterTitleView.h"
|
|
#import "TLSettingButtonCell.h"
|
|
|
|
@interface TLSettingViewController ()
|
|
|
|
@end
|
|
|
|
@implementation TLSettingViewController
|
|
|
|
- (void)loadView
|
|
{
|
|
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, HEIGHT_SCREEN)];
|
|
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
|
|
[self.tableView setTableHeaderView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, HEIGHT_SETTING_TOP_SPACE)]];
|
|
[self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, HEIGHT_SETTING_BOTTOM_SPACE)]];
|
|
[self.tableView setBackgroundColor:[UIColor colorGrayBG]];
|
|
[self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 15, 0, 0)];
|
|
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 0)];
|
|
[self.tableView setSeparatorColor:[UIColor colorGrayLine]];
|
|
}
|
|
|
|
- (void)viewDidLoad
|
|
{
|
|
[super viewDidLoad];
|
|
|
|
[self.tableView registerClass:[TLSettingHeaderTitleView class] forHeaderFooterViewReuseIdentifier:@"TLSettingHeaderTitleView"];
|
|
[self.tableView registerClass:[TLSettingFooterTitleView class] forHeaderFooterViewReuseIdentifier:@"TLSettingFooterTitleView"];
|
|
[self.tableView registerClass:[TLSettingCell class] forCellReuseIdentifier:@"TLSettingCell"];
|
|
[self.tableView registerClass:[TLSettingButtonCell class] forCellReuseIdentifier:@"TLSettingButtonCell"];
|
|
[self.tableView registerClass:[TLSettingSwitchCell class] forCellReuseIdentifier:@"TLSettingSwitchCell"];
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
{
|
|
[super viewWillAppear:animated];
|
|
[MobClick beginLogPageView:self.analyzeTitle];
|
|
}
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
{
|
|
[super viewWillDisappear:animated];
|
|
[MobClick endLogPageView:self.analyzeTitle];
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
#ifdef DEBUG_MEMERY
|
|
NSLog(@"dealloc %@", self.navigationItem.title);
|
|
#endif
|
|
}
|
|
|
|
#pragma mark - Delegate -
|
|
//MARK: UITableViewDataSource
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
{
|
|
return self.data.count;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
return [self.data[section] count];
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
TLSettingItem *item = [self.data[indexPath.section] objectAtIndex:indexPath.row];
|
|
id cell = [tableView dequeueReusableCellWithIdentifier:item.cellClassName];
|
|
[cell setItem:item];
|
|
if (item.type == TLSettingItemTypeSwitch) {
|
|
[cell setDelegate:self];
|
|
}
|
|
return cell;
|
|
}
|
|
|
|
//MARK: UITableViewDelegate
|
|
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
|
{
|
|
TLSettingGroup *group = self.data[section];
|
|
if (group.headerTitle == nil) {
|
|
return nil;
|
|
}
|
|
TLSettingHeaderTitleView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"TLSettingHeaderTitleView"];
|
|
[view setText:group.headerTitle];
|
|
return view;
|
|
}
|
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
|
|
{
|
|
TLSettingGroup *group = self.data[section];
|
|
if (group.footerTitle == nil) {
|
|
return nil;
|
|
}
|
|
TLSettingFooterTitleView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"TLSettingFooterTitleView"];
|
|
[view setText:group.footerTitle];
|
|
return view;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
[tableView deselectRowAtIndexPath:indexPath animated:NO];
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
return HEIGHT_SETTING_CELL;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
{
|
|
TLSettingGroup *group = self.data[section];
|
|
return 0.5 + (group.headerTitle == nil ? 0 : 5.0f + group.headerHeight);
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
|
{
|
|
TLSettingGroup *group = self.data[section];
|
|
return 20.0f + (group.footerTitle == nil ? 0 : 5.0f + group.footerHeight);
|
|
}
|
|
|
|
//MARK: TLSettingSwitchCellDelegate
|
|
- (void)settingSwitchCellForItem:(TLSettingItem *)settingItem didChangeStatus:(BOOL)on
|
|
{
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Switch事件未被子类处理" message:[NSString stringWithFormat:@"Title: %@\nStatus: %@", settingItem.title, (on ? @"on" : @"off")] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
|
|
[alert show];
|
|
}
|
|
|
|
#pragma mark - Getter -
|
|
- (NSString *)analyzeTitle
|
|
{
|
|
if (_analyzeTitle == nil) {
|
|
return self.navigationItem.title;
|
|
}
|
|
return _analyzeTitle;
|
|
}
|
|
|
|
@end
|