<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

    We often need to add social features in our iPhone apps. Adding features like commenting, shouts etc are very common. These type of data are usually shown
    with pagination with buttons like next, previous etc.

    To reduce the overhead of creating this functionality again and again we may encapsulate the common functions in a class. So did I for my applications.

    I have created a class named PaginationAgent. After loading records it calls related methods of its delegate which should implement protocol PaginationAgentDeleagte.

    Additionally two php files are needed. One to return the total number of records and another one is to fetch the page data. They must be named respectively as

    • get_total_number_of_records.php
    • get_records.php

    Lets see an example.

    First, I have created a simple view based project “Pagination” and designed the view as u see:

    Create a similar view using Interface Builder

    1. Added a button to show previous page data

    2. One button to reload the data.

    3. Another to show data on next page.

    4. Added a UITable which will show the result.

    In PaginationViewController.h, imported PaginationAgent.h file and declared:

    1. PaginationAgent* objPagination;  

    Now lets see how to initialize it. In the viewDidLoad method I initialized this like this:

    1. objPagination = [[PaginationAgent alloc] init];  
    2. objPagination.delegate = self;  
    3. objPagination.remoteApiBasePath = @"http://your.server/path/to/folder";  

    remoteApiBasePath must be set to the location where the server side php files are placed.
    No trailing slash.

    PaginationAgentDelegate protocol declares the following functions to be overridden by the Delegate:

    1. /** 
    2. * This method is called when the busystate is changed. 
    3. * You can do something like disable/enable the buttons, grayout etc 
    4. * based on the isBusy value. 
    5. */  
    6. -(void)paginationAgent:(PaginationAgent*)agent updateBusyMode:(BOOL)isBusy;  
    7.   
    8. /** 
    9. * Called when total data count is received if shouldReloadAtFirstPage is set NO. 
    10. */  
    11. -(void)paginationAgent:(PaginationAgent*)agent totalDataCountReceived:(int)dataCount;  
    12.   
    13. /** 
    14. * Called when page data is loaded. You may set your table dataSource here and realod 
    15. * reload the table. 
    16. */  
    17. -(void)paginationAgent:(PaginationAgent*)agent pageDataReceived:(NSArray*)data;  
    18.   
    19. /** 
    20. * Called if server sends malformed data 
    21. */  
    22. -(void)paginationAgent:(PaginationAgent*)agent onPaginationServerError:(NSString*)message;  
    23.   
    24. /** 
    25. * Called if connection failed. It may occur due to poor or no internet connectivity 
    26. */  
    27. -(void)paginationAgent:(PaginationAgent*)agent onPaginationConnectionError:(NSString*)message;  

    The php files must return data in json format and must use the format as used:

    1. 1,'message'=>'Success','data'=>33);  
    2.     echo json_encode($data);  
    3.   
    4. ?>  
    1. ...  
    2. ...  
    3. $data = array('success'=>1,'message'=>'Got data','data'=>$rows);  
    4.   
    5. echo json_encode($data);  

    See the attached project for details. The php files are inside the folder “PHPFILES”.

    Pagination.zip

    posted on 2010-10-08 21:30 seal 閱讀(263) 評論(0)  編輯  收藏 所屬分類: iPhone
    主站蜘蛛池模板: 亚洲AV无码一区东京热| 亚洲卡一卡二卡乱码新区| 91嫩草免费国产永久入口| 亚洲综合av一区二区三区不卡| 四虎影视精品永久免费网站| 少妇性饥渴无码A区免费| 亚洲乱码卡一卡二卡三| 免费一级成人毛片| 美女内射无套日韩免费播放| 欧美亚洲国产SUV| 亚洲av无码乱码国产精品| 日韩午夜免费视频| 久久香蕉国产线看免费| 亚洲AV成人精品一区二区三区| 亚洲成a人片在线观看无码| 色吊丝最新永久免费观看网站| 在线观看肉片AV网站免费| 亚洲a∨无码精品色午夜| 亚洲人成电影亚洲人成9999网| 免费观看午夜在线欧差毛片| 国产一卡二卡四卡免费| 三级黄色免费观看| 欧美色欧美亚洲另类二区| 亚洲二区在线视频| 亚洲av日韩av无码黑人| 亚洲精品亚洲人成在线观看下载 | 色五月五月丁香亚洲综合网| 亚洲午夜精品久久久久久人妖| 免费a级毛片在线观看| 91在线视频免费播放| 国产高清不卡免费视频| 一级做a爰性色毛片免费| 亚洲日韩一区二区一无码| 久久精品九九亚洲精品| 亚洲欧洲无码AV电影在线观看| 凹凸精品视频分类国产品免费| 性xxxx视频播放免费| 91免费精品国自产拍在线不卡| 一级毛片免费观看| 美女被免费网站91色| 一级看片免费视频|