

//初始化分段控制器
-(UISegmentedControl * )segment
{
if(!_segment)
{
//设置分段控制器的内容
_segment=[[UISegmentedControl alloc]initWithItems:@[@"攻略",@"训练营",@"资讯"]];
//设置分段控制器的位置
_segment.frame=CGRectMake(20, 0, self.view.frame.size.width-40, 40);
[_segment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
}
return _segment;
}
//初始化表格
-(UITableView * )tbv
{
if(!_tbv)
{
_tbv=[[UITableView alloc]initWithFrame:CGRectMake(3, 100, self.view.frame.size.width-6, self.view.frame.size.height-80) style:UITableViewStylePlain];
_tbv.delegate=self;
_tbv.dataSource=self;
}
return _tbv;
}
- (void)viewDidLoad {
[super viewDidLoad];
//设置导航不透明
self.navigationController.navigationBar.translucent=NO;
//设置主视图背景颜色
self.view.backgroundColor=[UIColor whiteColor];
//设置分段控制器的位置,添加到导航条
self.navigationItem.titleView=self.segment;
//初始化数组
self.dataArr=[NSMutableArray new];
self.feileiArr=[NSMutableArray new];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * string=@"string";
myTableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:string];
if(!cell)
{
cell=[[myTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string];
}
SuDuModel * sd=self.dataArr[indexPath.row];
[cell.imgv sd_setImageWithURL:[NSURL URLWithString:sd.photo]];
cell.zhu.text=sd.title;
cell.fu.text=sd.suitIntro;
cell.look.text=sd.readNum;
UILabel * label=[[UILabel alloc]initWithFrame:CGRectMake(340, 115, 50, 40)];
label.text=@"👁";
[cell addSubview:label];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 170;
}
//实现分段控制器的方法
-(void)change:(UISegmentedControl * )sender
{
if(sender.selectedSegmentIndex==0)
{
NSLog(@"1");
//设置全部攻略的label
UILabel * label=[[UILabel alloc]initWithFrame:CGRectMake(3, 10, 150, 40)];
label.text=@"全部攻略";
label.font=[UIFont systemFontOfSize:20];
[self.view addSubview:label];
//拼接字符串网址
NSString * onestring=[NSString stringWithFormat:@"%@%@",GongGong,FenLei];
AFHTTPSessionManager * manager=[AFHTTPSessionManager manager];
[manager GET:onestring parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"--------%@",responseObject);
//打印totalProperty判断分类按钮的数量
id shuliang=responseObject[@"totalProperty"];
NSLog(@"+++++++++%@",shuliang);
//获取data里面的元素
NSArray * arr=responseObject[@"data"];
//遍历
for (NSDictionary * dic in arr) {
FeiLeiModel * feilei=[FeiLeiModel mj_objectWithKeyValues:dic];
[self.feileiArr addObject:feilei];
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"error=%@",error);
}];
NSLog(@"\\\\\\\\\\\\\\\\%@",self.feileiArr);
//数量为4,根据内容创建四个按钮
//初始化速度按钮
self.btn=[[UIButton alloc]initWithFrame:CGRectMake(2, 60, self.view.frame.size.width/4-6, 40)];
[self.btn addTarget:self action:@selector(sudu) forControlEvents:UIControlEventTouchUpInside];
[self.btn setTitle:@"速度" forState:UIControlStateNormal];
[self.btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.btn.backgroundColor=[UIColor lightGrayColor];
self.btn.layer.masksToBounds=YES;
self.btn.layer.cornerRadius=20;
[self.view addSubview:self.btn];
//初始化技巧按钮
self.twoBtn=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4, 60, self.view.frame.size.width/4-6, 40)];
[self.twoBtn setTitle:@"技巧" forState:UIControlStateNormal];
[self.twoBtn addTarget:self action:@selector(jiqiao) forControlEvents:UIControlEventTouchUpInside];
[self.twoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.twoBtn.backgroundColor=[UIColor lightGrayColor];
self.twoBtn.layer.masksToBounds=YES;
self.twoBtn.layer.cornerRadius=20;
[self.view addSubview:self.twoBtn];
//初始化姿势按钮
self.threeBtn=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4*2, 60, self.view.frame.size.width/4-6, 40)];
[self.threeBtn setTitle:@"姿势" forState:UIControlStateNormal];
[self.threeBtn addTarget:self action:@selector(zishi) forControlEvents:UIControlEventTouchUpInside];
[self.threeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.threeBtn.backgroundColor=[UIColor lightGrayColor];
self.threeBtn.layer.masksToBounds=YES;
self.threeBtn.layer.cornerRadius=20;
[self.view addSubview:self.threeBtn];
//初始化进球按钮
self.fourBtn=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4*3, 60, self.view.frame.size.width/4-6, 40)];
[self.fourBtn setTitle:@"进球" forState:UIControlStateNormal];
[self.fourBtn addTarget:self action:@selector(jinqiu) forControlEvents:UIControlEventTouchUpInside];
[self.fourBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.fourBtn.backgroundColor=[UIColor lightGrayColor];
self.fourBtn.layer.masksToBounds=YES;
self.fourBtn.layer.cornerRadius=20;
[self.view addSubview:self.fourBtn];
}
else if(sender.selectedSegmentIndex==1)
{
NSLog(@"2");
UIView * view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
view.backgroundColor=[UIColor whiteColor];
[self.view addSubview:view];
}
else if(sender.selectedSegmentIndex==2)
{
NSLog(@"3");
UIView * oneview=[[UIView alloc]initWithFrame:self.view.frame];
oneview.backgroundColor=[UIColor whiteColor];
[self.view addSubview:oneview];
}
}
//实现速度按钮的点击方法
-(void)sudu
{
self.btn.backgroundColor=[UIColor blueColor];
self.twoBtn.backgroundColor=[UIColor lightGrayColor];
self.threeBtn.backgroundColor=[UIColor lightGrayColor];
self.fourBtn.backgroundColor=[UIColor lightGrayColor];
//添加表格到主视图
[self.view addSubview:self.tbv];
//拼接网址字符串
NSString * string=[NSString stringWithFormat:@"%@%@",GongGong,XiangDui];
//封装请求参数为字典
NSDictionary * dic=@{@"strategyType":@"攻略分类"};
AFHTTPSessionManager * manager=[AFHTTPSessionManager manager];
[manager GET:string parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"00000000000000%@",responseObject);
NSArray * arr=responseObject[@"data"];
for (NSDictionary * dic in arr) {
SuDuModel * sudu=[SuDuModel mj_objectWithKeyValues:dic];
[self.dataArr addObject:sudu];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tbv reloadData];
});
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@",error);
}];
}
//实现技巧按钮的点击方法
-(void)jiqiao
{
self.btn.backgroundColor=[UIColor lightGrayColor];
self.twoBtn.backgroundColor=[UIColor blueColor];
self.threeBtn.backgroundColor=[UIColor lightGrayColor];
self.fourBtn.backgroundColor=[UIColor lightGrayColor];
UIView * view=[[UIView alloc]initWithFrame:CGRectMake(3, 100, self.view.frame.size.width-6, self.view.frame.size.height-80)];
view.backgroundColor=[UIColor whiteColor];
[self.view addSubview:view];
}
//实现姿势按钮的点击方法
-(void)zishi
{
self.btn.backgroundColor=[UIColor lightGrayColor];
self.twoBtn.backgroundColor=[UIColor lightGrayColor];
self.threeBtn.backgroundColor=[UIColor blueColor];
self.fourBtn.backgroundColor=[UIColor lightGrayColor];
UIView * view=[[UIView alloc]initWithFrame:CGRectMake(3, 100, self.view.frame.size.width-6, self.view.frame.size.height-80)];
view.backgroundColor=[UIColor whiteColor];
[self.view addSubview:view];
}
//实现进球按钮的点击方法
-(void)jinqiu
{
self.btn.backgroundColor=[UIColor lightGrayColor];
self.twoBtn.backgroundColor=[UIColor lightGrayColor];
self.threeBtn.backgroundColor=[UIColor lightGrayColor];
self.fourBtn.backgroundColor=[UIColor blueColor];
UIView * view=[[UIView alloc]initWithFrame:CGRectMake(3, 100, self.view.frame.size.width-6, self.view.frame.size.height-80)];
view.backgroundColor=[UIColor whiteColor];
[self.view addSubview:view];
}
网友评论