请求网络接口 展示表格 厉害

SDK:AFNetworking+MJExtension+SDWebImage

Image:10套

Model:FeiLeiModel.h.m    SuDuModel.h.m

View : mytableviewCell.h.m

Controller : findviewcontroller.h.m   myviewcontroller.h.m  


Feilei.h

@interfaceFeiLeiModel :NSObject

@property(nonatomic,strong)NSString * text;

@end

-----------------

SuDuModel.h

@interfaceSuDuModel :NSObject

@property(nonatomic,strong)NSString * title;

@property(nonatomic,strong)NSString * suitIntro;

@property(nonatomic,strong)NSString * readNum;

@property(nonatomic,strong)NSString * photo;

@end

--------------------

mytableviewcell.h

@interfacemyTableViewCell :UITableViewCell

@property(nonatomic,strong)UIImageView * imgv;

@property(nonatomic,strong)UILabel * zhu;

@property(nonatomic,strong)UILabel * fu;

@property(nonatomic,strong)UILabel * look;

@end

----------------------

mytableviewcell.m


#import "myTableViewCell.h"

@implementationmyTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier

{

    if(self=[superinitWithStyle:stylereuseIdentifier:reuseIdentifier])

    {

        [selfaddSubview:self.imgv];

        [selfaddSubview:self.zhu];

        [selfaddSubview:self.fu];

        [selfaddSubview:self.look];

    }

    return self;

}

-(UIImageView * )imgv

{

    if(!_imgv)

    {

        _imgv=[[UIImageView alloc]initWithFrame:CGRectMake(3, 10, 200, 150)];


    }

    return _imgv;

}

-(UILabel* )zhu

{

    if(!_zhu)

    {

    _zhu=[[UILabel alloc]initWithFrame:CGRectMake(210, 10, 210, 40)];

        _zhu.font=[UIFont systemFontOfSize:20];

    }

    return _zhu;

}

-(UILabel* )fu

{

    if(!_fu)

    {

        _fu=[[UILabel alloc]initWithFrame:CGRectMake(210, 60, 210, 40)];

        _fu.font=[UIFont systemFontOfSize:16];

        _fu.textColor=[UIColor lightGrayColor];

        _fu.numberOfLines=0;


    }

    return _fu;

}

-(UILabel* )look

{

    if(!_look)

    {

        _look=[[UILabel alloc]initWithFrame:CGRectMake(350, 120, 50, 30)];


        _look.textColor=[UIColor lightGrayColor];


        _look.textAlignment=NSTextAlignmentRight;

    }

    return _look;

}

- (void)awakeFromNib {

    [super awakeFromNib];

    // Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [supersetSelected:selectedanimated:animated];

    // Configure the view for the selected state

}

@end

------------------------

appdelegate.h


#import

#import

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property(readonly,strong)NSPersistentContainer*persistentContainer;

- (void)saveContext;

@end

------------------------------

appdelegate.m


#import "AppDelegate.h"

#import "ViewController.h"

#import "findViewController.h"

#import "myViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {


    UINavigationController * vcNav=[[UINavigationController alloc]initWithRootViewController:[ViewController new]];


    vcNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"报告" image:[UIImage imageNamed:@"消息灰.png"] selectedImage:[UIImage imageNamed:@"消息蓝.png"]];




    UINavigationController * findNav=[[UINavigationController alloc]initWithRootViewController:[findViewController new]];


    findNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"发现" image:[UIImage imageNamed:@"喜欢灰.png"] selectedImage:[UIImage imageNamed:@"喜欢蓝.png"]];



    UINavigationController * myNav=[[UINavigationController alloc]initWithRootViewController:[myViewController new]];


    myNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"我" image:[UIImage imageNamed:@"我的灰.png"] selectedImage:[UIImage imageNamed:@"我的蓝.png"]];



    UITabBarController * tbc=[[UITabBarController alloc]init];


    tbc.viewControllers=@[vcNav,findNav,myNav];


    self.window.rootViewController=tbc;


    return YES;

}

-----------------------

viewcontroller.m


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor=[UIColor redColor];

}

@end

-----------------------------

findviewcon.m


#define FenLei @"enumeration/list?type=StrategyType"

#define GongGong @"http://124.65.238.30:3300/bingyun/api/"

#define XiangDui @"strategy/page?pageNo=1&pageSize=10&strategyType=POSTURE"

#import "findViewController.h"

#import "myTableViewCell.h"

#import "AFNetworking.h"

#import "UIImageView+WebCache.h"

#import "MJExtension.h"

#import "FeiLeiModel.h"

#import "SuDuModel.h"

@interface findViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UISegmentedControl * segment;

@property(nonatomic,strong)UITableView * tbv;

@property(nonatomic,strong)NSMutableArray * dataArr;

@property(nonatomic,strong)NSMutableArray * feileiArr;

@property(nonatomic,strong)UIButton * btn;

@property(nonatomic,strong)UIButton * twoBtn;

@property(nonatomic,strong)UIButton * threeBtn;

@property(nonatomic,strong)UIButton * fourBtn;

@end

@implementationfindViewController

//初始化分段控制器

-(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

{

    staticNSString* string=@"string";


    myTableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:string];


    if(!cell)

    {

        cell=[[myTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string];

    }

    SuDuModel* sd=self.dataArr[indexPath.row];


    [cell.imgvsd_setImageWithURL:[NSURLURLWithString: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=@"👁";


    [celladdSubview:label];

    returncell;

}

-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath

{

    return 170;

}

//实现分段控制器的方法

-(void)change:(UISegmentedControl* )sender

{

    if(sender.selectedSegmentIndex==0)

    {

        NSLog(@"1");

        //设置全部攻略的label

        UILabel* label=[[UILabelalloc]initWithFrame:CGRectMake(3,10,150,40)];

        label.text=@"全部攻略";


        label.font=[UIFontsystemFontOfSize:20];


        [self.viewaddSubview:label];


        //拼接字符串网址

        NSString* onestring=[NSStringstringWithFormat:@"%@%@",GongGong,FenLei];


        AFHTTPSessionManager * manager=[AFHTTPSessionManager manager];


        [managerGET:onestringparameters:nilsuccess:^(NSURLSessionDataTask*task,idresponseObject) {

            NSLog(@"--------%@",responseObject);


            //打印totalProperty判断分类按钮的数量

            idshuliang=responseObject[@"totalProperty"];

            NSLog(@"+++++++++%@",shuliang);


            //获取data里面的元素

            NSArray* arr=responseObject[@"data"];


            //遍历

            for(NSDictionary* dicinarr) {

                FeiLeiModel* feilei=[FeiLeiModelmj_objectWithKeyValues:dic];



                [self.feileiArraddObject:feilei];

            }

        }failure:^(NSURLSessionDataTask*task,NSError*error) {

            NSLog(@"error=%@",error);

        }];

        NSLog(@"\\\\\\\\\\\\\\\\%@",self.feileiArr);




        //数量为4,根据内容创建四个按钮

        //初始化速度按钮

        self.btn=[[UIButtonalloc]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.viewaddSubview: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.viewaddSubview: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.viewaddSubview: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.viewaddSubview: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.viewaddSubview:view];

    }

    elseif(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,idresponseObject) {

        NSLog(@"00000000000000%@",responseObject);


        NSArray * arr=responseObject[@"data"];


        for(NSDictionary * dicinarr) {

            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];


}

@end

=====================

myviewcotroller.m

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor=[UIColor blueColor];

}

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,884评论 6 513
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,212评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 167,351评论 0 360
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,412评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,438评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,127评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,714评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,636评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,173评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,264评论 3 339
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,402评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,073评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,763评论 3 332
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,253评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,382评论 1 271
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,749评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,403评论 2 358

推荐阅读更多精彩内容