`
knight_black_bob
  • 浏览: 842401 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

iOS mjrefresh 使用

    博客分类:
  • ios
阅读更多

 



 
 


 
 

 

TableViewController.h

//
//  TableViewContoller.h
//  IteyeBlog
//
//  Created by youbao on 16/10/15.
//  Copyright © 2016年 youbao. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface TableViewContoller : UIViewController





@end

 

 

TableViewController.m

 

//
//  TableViewContoller.m
//  IteyeBlog
//
//  Created by youbao on 16/10/15.
//  Copyright © 2016年 youbao. All rights reserved.
//

#import "TableViewContoller.h"
#import "TableViewCell.h"
#import   "UIImageView+WebCache.h"
#import "OfferEntity.h"
#import "MJRefresh.h"



static NSString *const IconUrl = @"http://ods5pg0qp.bkt.clouddn.com/iteyeblog/icon.png";


@interface TableViewContoller ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, retain)   NSMutableArray  *mDataArray;


@end


@implementation TableViewContoller


#pragma mark - init
#pragma mark   初始化数据
- (NSArray *)mDataArray{
    
    if (!_mDataArray) {
        OfferEntity *entity = [[OfferEntity alloc] init];
        entity.iconurl = IconUrl;
        entity.name = @"baoyou";
        entity.desc = @"IT 工程师";
        
        self.mDataArray = [NSMutableArray array];
        for (int i = 0; i<5; i++) {
            [self.mDataArray addObject:entity];
        }
    }
    return _mDataArray;
}

#pragma mark - 视图管理
#pragma mark   viewdidload
-(void) viewDidLoad{

    [super viewDidLoad];

    NSLog(@"==========view did load=============");
    
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self onRresh];
    }];
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onLoadMore)];
}



#pragma mark - request
#pragma mark    请求数据
static int currentPage = 0;
static int defualtPageSize = 15;
-(void) onRequest:(int) currIndex{
    if(currIndex == 0){
    
        OfferEntity *entity3 = [[OfferEntity alloc] init];
        entity3.iconurl = IconUrl;
        entity3.name = @"baoyou3";
        entity3.desc = @"IT 工程师3";
        
        [self.mDataArray insertObject:entity3 atIndex:0];
        
    }else{
    
        
    }
    
    
    [self.tableView reloadData];
    
    [self.tableView.mj_header endRefreshing];
    
    if( [_mDataArray count] % defualtPageSize == 0){
        [self.tableView.mj_footer endRefreshing];
    }else{
        [self.tableView.mj_footer resetNoMoreData] ;
    }

    
    
    
}

- (void) onRresh{
    currentPage = 0;
    
    [self onRequest:currentPage];
}
-(void) onLoadMore{
    currentPage += 1;
    [self onRequest:currentPage];
}




#pragma mark - uitableview method
#pragma mark   返回有多少个Sections
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
#pragma mark  对应的section有多少个元素,也就是多少行
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
    return [self.mDataArray count];
}
#pragma mark  指定的 row 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return  100.f;
}

#pragma mark  每行cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    //NSDictionary *item = [self.mDataArray objectAtIndex:indexPath.row];
    OfferEntity *entity =  self.mDataArray[indexPath.row];
    NSLog(@"=================%@",entity );
    
    static NSString * cellIdentifier = @"tableView";
    TableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil){
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
            cell = (TableViewCell *)[nib objectAtIndex:0];
    }
    
       [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString: entity.iconurl ]  placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    
     cell.name.text = entity.name;
     cell.desctription.text = entity.desc;
    
    cell.onClick = ^(void){
        NSLog(@"=================");
        NSLog(@"%ld",indexPath.row);
    };
    
    return  cell;
}

#pragma mark  点击行,可以做跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}


@end

 

 

//
//  TableViewCell.h
//  IteyeBlog
//
//  Created by youbao on 16/10/15.
//  Copyright © 2016年 youbao. All rights reserved.
//

#import <UIKit/UIKit.h>

typedef void( ^ onClick)();


@interface TableViewCell : UITableViewCell


@property (weak, nonatomic) IBOutlet UIImageView * iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *desctription;



@property (nonatomic, copy)    onClick onClick;
//@property (nonatomic, copy)     void ( ^ onClick) (void);

@end

 

 

//
//  TableViewCell.m
//  IteyeBlog
//
//  Created by youbao on 16/10/15.
//  Copyright © 2016年 youbao. All rights reserved.
//

#import "TableViewCell.h"


@interface TableViewCell ()



@end


@implementation TableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onImageClick:)];
    [self.iconImageView addGestureRecognizer:singleTap];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)onImageClick:(UIButton *)sender{
if(self.onClick)
    self.onClick();
}



@end

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

 

 

 

  • 大小: 123.9 KB
  • 大小: 53.2 KB
  • 大小: 147.1 KB
0
1
分享到:
评论

相关推荐

    基于ios MJRefresh 开发的插件,可提供自定义的弹性刷新.zip

    基于ios MJRefresh 开发的插件,可提供自定义的弹性刷新.zip,基于ios MJRefresh https://github.com/CoderMJLee/MJRefresh 开发的插件,可提供自定义的弹性刷新

    ios-MJRefresh优化.zip

    在iOS开发中,MJRefresh是一个广泛使用的开源库,它提供了下拉刷新和上拉加载更多的功能,使得开发者能够轻松地为应用添加这类交互效果。针对MJRefresh的优化,主要是为了提高用户体验,减少性能消耗,以及确保其在...

    UICollectionView详解并解决MJRefresh下拉刷新遮挡问题

    本篇文章将深入探讨UICollectionView的使用方法,并解决在集成MJRefresh下拉刷新时可能出现的遮挡问题。 首先,我们来详细了解UICollectionView。它允许开发者自定义布局,支持水平和垂直滚动,甚至可以创建复杂的...

    iOS上拉加载更多和下拉刷新mjrefresh使用

    "iOS上拉加载更多和下拉刷新mjrefresh使用"这一主题,主要关注的是利用第三方库MJRefresh来实现这两个功能。MJRefresh是一个流行的、易于使用的Swift或Objective-C库,它提供了丰富的动画效果和高度自定义的选项,让...

    iPhoneX MJRefresh 使用

    MJRefresh框架,作为一个广泛使用的开源库,提供了对各种iOS设备的兼容性,包括具有安全区域布局的iPhoneX。本教程将指导开发者如何在不同iPhone型号上集成MJRefresh,并特别关注如何进行iPhoneX的适配工作,确保...

    iOS利用MJRefresh实现自定义刷新动画效果

    总结一下,本文介绍了如何在iOS应用中使用MJRefresh库实现自定义动画的刷新和加载效果。通过创建图片数组并设置到`MJRefreshGifHeader`和`MJRefreshAutoGifFooter`组件中,可以轻松地实现个性化的下拉刷新和上拉加载...

    MJRefresh兼容ios11demo

    MJRefresh是一个广泛使用的开源库,它为Objective-C和Swift开发者提供了下拉刷新和上拉加载更多的功能。 【描述分析】 描述中提到,这个demo基于MJRefresh的原始代码,但做了一些小改动以适应iOS 11的新特性。...

    iOS上下拉刷新控件MJRefresh使用方法详解

    在github上下载之后,将MJRefresh文件添加到项目中,并且在需要使用的文件上引入MJRefresh.h。然后在该文件的viewDidLoad方法中指定tableView的header和footer,如下: #import MJRefreshTableViewController.h #...

    iOS 下拉刷新 MJRefresh.zip

    MJRefresh是一个广泛使用的开源库,它为Objective-C编程语言提供了简单易用的下拉刷新和上拉加载更多解决方案。这个库由iOS开发者Michael Jiang创建,大大简化了在UITableView和UICollectionView中实现这些动态刷新...

    ios-基于MJRefresh刷新库,自定义刷新样式MJRefreshHeader,使用贝塞尔曲线绘制的.zip

    github地址:https://github.com/eppeo/FootBallRefreshView 博客:www.wufeiyue.com 简书:http://www.jianshu.com/users/a3c05f95bce8

    iOS的UITableView开源包,MJRefresh上下拉刷新

    为了在项目中使用MJRefresh,开发者首先需要将MJRefresh库添加到项目中,这可以通过CocoaPods、Carthage或者手动导入完成。然后,只需几行代码即可实现上下拉刷新功能: ```objc // 下拉刷新 [self.tableView....

    ios-swift版的类似MJRefresh方便自定义的上下拉刷新控件.zip

    这个名为"ios-swift版的类似MJRefresh方便自定义的上下拉刷新控件"的压缩包,正是为满足这种需求而设计的。 该压缩包内包含的PullToRefresh文件夹,很可能是实现这一功能的核心代码。在Swift中,我们可以创建自定义...

    MJRefresh_Xamarin.iOS:适用于Xamrin.iOS的MJRefresh dll

    对于MJRefresh,有开发者已经完成了这个绑定过程,使得我们能够在Xamarin.iOS项目中直接使用MJRefresh的功能。 4. **NuGet**: NuGet是.NET生态中的包管理器,开发者可以使用它来查找、安装、更新和卸载软件包。在...

    MJRefresh无感刷新

    MJRefresh无感刷新 项目开发中用了MJRefres 刷新控件,每次上拉的时候都有个菊花转,需要下拉一下才能看到下一页的数据。产品提出需求,希望列表往下拉能直接出现下一页的数据,不需要出现加载的动画和等待时间。...

    iOS实现MJRefresh下拉刷新(上拉加载)使用详解

    本文将详细介绍如何使用MJRefresh库来实现这一功能。MJRefresh是一个强大的、高度可定制的下拉刷新和上拉加载框架,它提供了丰富的样式和自定义选项。 首先,要将MJRefresh库引入到你的iOS项目中。你可以通过...

    MJRefresh库

    在iOS开发中,下拉刷新与上拉加载更多是常见的功能需求,而MJRefresh库就是一款专为此目的设计的开源组件。它由著名iOS开发者Michael Jason(MJ)创建,旨在简化应用中实现刷新逻辑的复杂度,提供了一套简单易用、...

    mj_refresh 上拉、下拉、自定义header、footer、afn子类化案例

    mj_refresh 上拉、下拉、自定义header、footer、afn子类化案例,博客地址https://blog.csdn.net/dreams_deng/article/details/106691104

    MJRefresh 非常好用的IOS 开发 表格 不下载你后悔

    因此,如果你正在进行iOS应用开发,尤其是涉及列表刷新功能,不使用MJRefresh可能会错过一个非常实用的工具,确实会有些许遗憾。 综上所述,MJRefresh是一个强大的iOS下拉刷新框架,适用于UITableView和...

    下拉刷新上啦加载MJRefresh

    【下拉刷新上啦加载MJRefresh】是一种广泛应用于iOS应用中的功能,主要用于更新表格视图(UITableView或UICollectionView)的数据。这个功能使得用户可以方便地获取最新的数据,无需手动刷新整个页面。MJRefresh是由...

Global site tag (gtag.js) - Google Analytics