zoukankan      html  css  js  c++  java
  • 网络问题

    NSString*str = @"http://app.d1xz.net/xingzuoapp2/news?typ e=xingwen&page=1";

    NSURL*url = [NSURLURLWithString:str]; [self createData:url forType:1];//解析数

    [self.tableView addHeaderWithTarget:self action:@selector(refresh)];

    [self refresh];

    #pragma mark 下拉刷新 -(void)createData:(NSURL *)url forType:(int)type
    {

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

    if (connectionError) { NSLog(@"网络错误");
    UILabel *label = [[UILabel alloc]

    initWithFrame:CGRectMake(kScreenWidth / 3,

    page1image6520 page1image6680

    kScreenHeight / 2 - 10, kScreenWidth / 3, 40)];

    redColor];

    label.text = @"网络错误"; label.textColor = [UIColor

    [self.view addSubview:label];

    }else{

    NSDictionary *dataDic = [NSJSONSerialization

    JSONObjectWithData:data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];

    NSArray *dataArray = [dataDic objectForKey:@"content"];

    NSMutableArray *testArray = [NSMutableArray array];

    {

    for(NSDictionary *dicindataArray) MessageModel *messageM =

    [[MessageModel alloc] init];

    [messageM setValuesForKeysWithDictionary:dic];

    [testArray addObject:messageM];

    }
    if (type == 1) {

    self.inforArray = testArray;

    [self.tableView footerEndRefreshing];

    }else { [self.inforArray

    addObjectsFromArray:testArray]; [self.tableView

    footerEndRefreshing]; }

    }

    [self.tableView reloadData]; }];if

    }
    - (void)refresh {

    dispatch_after(dispatch_time(DISPATCH_ TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

    NSString *str = @"http://app.d1xz.net/xingzuoapp2/news?typ e=xingwen&page=1";

    NSURL *URL = [NSURL URLWithString:str];

    [self createData:URL forType:1]; [self.tableView reloadData];

    });

    [self.tableView headerEndRefreshing]; }

    #pragma mark 上拉加载 - (void)loadMore

    page3image7416 page3image7576

    {
    self.pages++;

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://app.d1xz.net/xin gzuoapp2/news?type=xingwen&page=%ld",(long )self.pages]];

    NSLog(@"%@", url);

    [self createData:url forType:2]; } 

  • 相关阅读:
    mysqldump详解
    mysql忽略表中的某个字段不查询
    mysqldumpslow基本使用
    xtrabakcup基本用法 安装、全量备份恢复、增量备份恢复
    Ubuntu--磁盘统计
    Ubuntu--硬盘的挂载与卸载
    Ubuntu--文件属性权限管理(command: chmod, chown)
    Ubuntu--useradd指令使用
    Ubuntu--安装sshd开启远程登陆服务
    Ubuntu--虚拟机中Ubuntu系统时间与windows不同步
  • 原文地址:https://www.cnblogs.com/lidongxiao/p/4949950.html
Copyright © 2011-2022 走看看