iOS development with afnetworking and Mjrefresh for network requests and drop-down refreshes, pull-up loading

Source: Internet
Author: User

First of all, thank iOS122 for the interface of the network data provided by the free GET request.

To facilitate cell adaptive height, the cell here is with Xib. To facilitate understanding of the code, there is no MVC design pattern applied here, which cannot be done in real-world development.

#import "ViewController.h" #import "AFNetworking.h" #import "MJRefresh.h" #import "TestTableViewCell.h" @interface Viewcontroller () <uitableviewdelegate, uitableviewdatasource> @property (nonatomic, strong) UITableView * TableView; @property (nonatomic, strong) Nsmutablearray *dataarray; @property (assign, nonatomic) int page;@    End@implementation viewcontrollerstatic NSString *identifier = @ "Cell";-(void) viewdidload {[Super viewdidload];        Self.dataarray = [Nsmutablearray array];    Self.tableview = [[UITableView alloc] init];    Self.tableView.frame = CGRectMake (0, 0, 375, 667);    Self.tableView.backgroundColor = [Uicolor colorwithred:0.635 green:1.000 blue:0.905 alpha:1.000];    Self.tableView.delegate = self;    Self.tableView.dataSource = self;    [Self.view AddSubview:self.tableView];    Cell adaptive height self.tableView.estimatedRowHeight = 100;        Self.tableView.rowHeight = uitableviewautomaticdimension; [Self.tableview registernib:[uinib nibwithnibname:@ "TesttablevIewcell "Bundle:nil] forcellreuseidentifier:identifier];        Self.tableView.mj_header = [Mjrefreshnormalheader headerwithrefreshingblock:^{self.page = 0;    [Self updatedata];    }];    Self.tableView.mj_footer = [Mjrefreshbacknormalfooter footerwithrefreshingblock:^{[self updatedata]; }];}    -(void) Viewwillappear: (BOOL) animated {[Super viewwillappear:animated]; [Self.tableView.mj_header beginrefreshing];} -(void) UpdateData {NSString * urlstr = [NSString stringwithformat:@ "Http://www.ios122.com/find_php/index.php?viewCon    Troller=yfpostlistviewcontroller&model[category]=ui&model[page]=%d ", self.page++];    Afhttpsessionmanager *manager = [Afhttpsessionmanager manager]; [Manager get:urlstr Parameters:nil progress:^ (nsprogress * _nonnull downloadprogress) {} success:^ (Nsurlsessiondatatask * _nonnull task, id _nullable responseobject) {[Self.tableView.mj_h        Eader endrefreshing]; [Self.tableView.mj_footer endrefreshing];        if (self.page = = 1) {//If it is a drop-down refresh data, remove all data, and then re-add the newly refreshed data for (; 0 < Self.dataArray.count;) {            [Self.dataarray removeobjectatindex:0]; }}//Add the refreshed data to the array after for (Nsmutabledictionary *item in Responseobject) {if (item! = (NS            Mutabledictionary *) [NSNull null]) {[Self.dataarray addobject:item];    }} [Self.tableview Reloaddata]; } failure:^ (Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) {[Self.tableView.mj_header Endrefresh        ING];    [Self.tableView.mj_footer endrefreshing]; }];} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return Self.dataArray.count;}    -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {    Testtableviewcell *cell = [TableView dequeuereusablecellwithidentifier:identifier Forindexpath:indexpath]; Cell.selectionstyle = Uitableviewcellselectionstylenone;    Nsdictionary *dict = Self.dataarray[indexpath.row]; NSString * content = [NSString stringwithformat:@ title:%@ Contents:%@ title:%@ content:%@ title:%@ content:%@ title:%@ content:%@ title:%@ content:%@ title:%@ content:%@ " , dict[@ "title"], dict[@ "desc"], dict[@ "title"], dict[@ "desc"], dict[@ "title"], dict[@ "desc"], dict[@ "title", dict[@ "    Desc "], dict[@" title "], dict[@" desc "], dict[@" title "], dict[@" desc "];    Cell.label.text = content;    Cell.label.numberOfLines = 0;    Cell.backgroundcolor = [Uicolor colorwithred:0.543 green:0.854 blue:1.000 alpha:1.000]; return cell;} @end

iOS development with afnetworking and Mjrefresh for network requests and drop-down refreshes, pull-up loading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.