#import "OneViewController.h"
#import "ImgShowViewController.h"
@interface OneViewController ()<UITableViewDelegate,UITableViewDataSource>
{
UITableView *table;
UISearchBar *search;
UISearchDisplayController *dis;
NSArray *imgArr;
NSArray *perArr;
NSArray *arr;
NSArray *subArr;
}
@end
@implementation OneViewController
-(void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
self.navigationController.navigationBar.backgroundColor=[UIColor redColor];
table =[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
table.dataSource=self;
table.delegate=self;
table.separatorColor =[UIColor greenColor];
[self.view addSubview:table];
arr =@[ @"信息",@"对话"];
UISegmentedControl *seg =[[UISegmentedControl alloc]initWithItems:arr];
seg.layer.cornerRadius=6;
seg.layer.masksToBounds=YES;
[seg addTarget:self action:@selector(selectSeg:) forControlEvents:UIControlEventValueChanged];
seg.selectedSegmentIndex=0;
self.navigationItem.titleView =seg;
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithTitle:@"嗖" style:UIBarButtonItemStylePlain target:self action:@selector(clickleftBar)];
self.navigationItem.leftBarButtonItem=leftItem;
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"撒" style:UIBarButtonItemStylePlain target:self action:@selector(addBar)];
self.navigationItem.rightBarButtonItem=rightItem;
search =[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
search.placeholder =@"搜索";
dis =[[UISearchDisplayController alloc]initWithSearchBar:search contentsController:self];
dis.searchResultsDataSource=self;
dis.searchResultsDelegate=self;
table.tableHeaderView=search;
perArr=@[@"小阿布",@"大白",@"陌陌",@"皮卡丘",@"丘比特",@"张百万",@"张有才",@"科比"];
imgArr=@[@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg"];
subArr=@[@"大好时光",@"晴空万里",@"大好时光",@"晴空万里",@"大好时光",@"晴空万里",@"大好时光",@"晴空万里"];
[self.view addSubview:table];
}
-(void)selectSeg:(UISegmentedControl *)ss
{
if (ss.selectedSegmentIndex ==1) {
table.hidden =YES;
ImgShowViewController *imgShow =[[ImgShowViewController alloc]init];
[self.navigationController pushViewController:imgShow animated:YES];
}else
{
table.hidden=NO;
}
}
-(void)clickleftBar
{
}
-(void)addBar
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"添加好友" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
alert.alertViewStyle=UIAlertViewStylePlainTextInput;
[alert show];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 8;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *str =@"s";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:str];
if (cell==nil) {
cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];
}
cell.textLabel.text =perArr[indexPath.row];
cell.textLabel.font =[UIFont systemFontOfSize:16];
cell.textLabel.textColor =[UIColor redColor];
// 设置副标题
cell.detailTextLabel.text=subArr[indexPath.row];
cell.detailTextLabel.font=[UIFont systemFontOfSize:12];
cell.detailTextLabel.textColor=[UIColor grayColor];
// 设置图片
cell.imageView.image=[UIImage imageNamed:[imgArr objectAtIndex:indexPath.row]];
cell.imageView.layer.cornerRadius=30;
cell.imageView.layer.masksToBounds=YES;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ImgShowViewController *imgShow =[[ImgShowViewController alloc]init];
[self.navigationController pushViewController:imgShow animated:YES];
}