• XML解析及上拉加载下拉刷新


    XML解析及上拉加载下拉刷新

    1.XML格式

      

    2.GData和XPath遍历

    //配置XML库(配置完才能使用)
     //(1)添加头文件搜索路径
     //      Header Search Paths-> /usr/include/libxml2
     //(2)添加二进制库
     //  Link library ->  lixml2.dylib
     //(3)源文件添加编译选项
     //      -fno-objc-arc
     //(4)添加头文件
     //  #import "GDataXMLNode.h"*/

      XPath 获取路径  --> 访问数据

     NSString *path = [[NSBundle mainBundle] pathForResource:@"xml" ofType:@"txt"];
    NSData
    *data = [[NSData alloc] initWithContentsOfFile:path]; //initWithData -- > 使用NSData初始化,解析 GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:nil]; //获取指定结点 XPath(路径) // CityName路径: /root/systemConfig/CityName NSArray *array = [doc nodesForXPath:@"/root/systemConfig/areaCode" error:nil]; GDataXMLElement *element = [array firstObject]; NSLog(@"name = %@,value = %@",element.name,element.stringValue); NSArray *items = [doc nodesForXPath:@"/root/systemConfig/ComeChannel/Item" error:nil]; GDataXMLElement *item = [items firstObject]; // item.attributes //属性 //获取所有属性 for(GDataXMLElement *attr in item.attributes){ NSLog(@"a-name = %@, a-value = %@",attr.name,attr.stringValue); } //4.获取所有指定名字的结点(不管位置) //XPath NSArray *allItem = [doc nodesForXPath:@"//Item" error:nil]; for(GDataXMLElement *e in allItem){ NSLog(@"name = %@",e.name); } //5.获取所有指定名字的值(不管位置) //XPath NSArray *allValue = [doc nodesForXPath:@"//@value" error:nil]; for(GDataXMLElement *e in allValue){ NSLog(@"value = %@",e.stringValue); } //获取根结点 GDataXMLElement *rootel = doc.rootElement; // NSArray *children = rootel.children; //获取子结点 // rootel.childCount //获取结点个数

    3.上拉加载及下拉刷新

      一般使用第三方开源库

         注:需刷新表格数据    

    #import "GDataXMLNode.h"
    #import "AAPullToRefresh.h"@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
    {
    
        ZJHttpRequest *_request;
        NSString *_city;
        NSString *_catagory;   //
        int _offset;   //几行
        int _pageSize;   //#pragma mark - 上拉刷新及下拉加载
    -(void)addapullRefreshAndPullLoadMore{
    
    //AAPullToRefresh
        //top
        AAPullToRefresh *tv = [_tableView addPullToRefreshPosition:AAPullToRefreshPositionTop actionHandler:^(AAPullToRefresh *v){
        
            _offset = 1;
            NSLog(@"fresh top");
            [v performSelector:@selector(stopIndicatorAnimation) withObject:nil afterDelay:1.0f];
            [self startDownloadData];
        }];
        tv.imageIcon = [UIImage imageNamed:@"launchpad"];
        tv.borderColor = [UIColor whiteColor];
        
        //buttom
        AAPullToRefresh *bv =[_tableView addPullToRefreshPosition:AAPullToRefreshPositionBottom actionHandler:^(AAPullToRefresh *v){
            
            _offset += _pageSize;
            NSLog(@"add buttom");
            [v performSelector:@selector(stopIndicatorAnimation) withObject:nil afterDelay:1.0f];
            [self startDownloadData];
        }];
        bv.imageIcon = [UIImage imageNamed:@"launchpad"];
        bv.borderColor = [UIColor whiteColor];
    
    }
  • 相关阅读:
    easyui struts后台实现tree返回json数据
    jquery扩展方法
    EasyUI tree扩展获取实心节点
    Hibernate之AbstractEntityPersister
    No CurrentSessionContext configured 异常解决
    Dubbo远程调用服务框架原理与示例
    mongodb高级操作及在Java企业级开发中的应用
    Java和MongoDB之Hello World
    Vmware 虚拟的Linux系统如何与宿主主机共享上网
    VM VirtualBox 上安装 CentOs6.4(详细)
  • 原文地址:https://www.cnblogs.com/wlrBlogs/p/4388288.html
Copyright © 2020-2023  润新知