#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView ;
@property (nonatomic,strong)NSArray *dataArray ;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"EasyShowView示例";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"展示" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarClick)];
[self.view addSubview:self.tableView] ;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)rightBarClick
{
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.dataArray.count ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dataArray[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
cell.textLabel.textColor = [UIColor blueColor];
cell.textLabel.text = self.dataArray[indexPath.section][indexPath.row];
return cell ;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.section) {
case 0:
if (indexPath.row==0) {
NSLog(@"第一组第一行");
} else if (indexPath.row==1) {
NSLog(@"第一组第二行");
} else if (indexPath.row==2) {
NSLog(@"第一组第三行");
} else if (indexPath.row==3) {
NSLog(@"第一组第四行");
} else if (indexPath.row==4) {
NSLog(@"第一组第四行");
} else if (indexPath.row==5) {
NSLog(@"第一组第五行");
}
break ;
case 1:
if (indexPath.row==0) {
NSLog(@"第二组第一行");
} else if (indexPath.row==1) {
NSLog(@"第二组第二行");
} else if (indexPath.row==2) {
NSLog(@"第二组第三行");
} else if (indexPath.row==3) {
NSLog(@"第二组第四行");
} else if (indexPath.row==4) {
NSLog(@"第二组第四行");
} else if (indexPath.row==5) {
NSLog(@"第二组第五行");
} else if (indexPath.row==6) {
NSLog(@"第二组第六行");
}
break ;
case 2:
if (indexPath.row==0) {
NSLog(@"第三组第一行");
} else if (indexPath.row==1) {
NSLog(@"第三组第二行");
} else if (indexPath.row==2) {
NSLog(@"第三组第三行");
}
break ;
case 3:
if (indexPath.row==0) {
NSLog(@"第四组第一行");
} else if (indexPath.row==1) {
NSLog(@"第四组第二行");
} else if (indexPath.row==2) {
NSLog(@"第四组第三行");
} else if (indexPath.row==3) {
NSLog(@"第四组第四行");
}
break ;
default: break;
}
}
#pragma mark - getter/setter
- (UITableView *)tableView
{
if (nil == _tableView) {
_tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
_tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellID"];
_tableView.dataSource = self ;
_tableView.delegate = self ;
}
return _tableView ;
}
- (NSArray *)dataArray
{
if (nil == _dataArray) {
_dataArray = @[
@[@"纯文字消息",@"成功消息",@"失败消息",@"提示消息",@"自定义图片"],
@[@"转圈加载框",@"菊花加载框",@"自定义图片加载框",@"图片翻转加载框",@"图片边框转圈",@"隐藏加载框"] ,
@[@"空页面(不可滚动)",@"空页面(所有子控件)",@"空页面(对superview外扩内收)"],
@[@"一行代码显示自定义alertView",@"ActionSheet",@"系统AlertView",@"系统ActionSheet(点2次)"]
];
}
return _dataArray ;
}
//下面是设置分组的头部和底部间距
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 50;//section头部高度
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//设置头部颜色
UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
headerView.backgroundColor = [UIColor blueColor];
//如果需要设置每组的头部标题,可如下进行
UILabel *label = [[UILabel alloc]init];
label.textColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:13];
label.frame = CGRectMake(15, 0, 200, 20);
label.textColor=[UIColor yellowColor];
[headerView addSubview:label];
label.text = [NSString stringWithFormat:@"第%ld组头部", (long)section];
if (section==1) {
label.text=@"此处我可以不设置头部标题";
}
return headerView ;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 30;//section底部高度
}
//section底部视图- (UIView
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
view.backgroundColor = [UIColor grayColor];
//如果需要设置每组的头部标题,可如下进行
UILabel *label = [[UILabel alloc]init];
label.textColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:13];
label.frame = CGRectMake(15, 0, 200, 20);
label.textColor=[UIColor yellowColor];
[view addSubview:label];
label.text = [NSString stringWithFormat:@"第%ld组尾部", (long)section];
if (section==1) {
label.text=@"此处我也可以不设置尾部标题";
}
return view;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end