MJRefresh实例练习

#pragma mark - 获取随机数
#define RandomData      [NSString stringWithFormat:@"随机数据---%d",arc4random_uniform(10000)]
#import "MyViewController.h"
#import "MJRefresh.h"

@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (strong, nonatomic) NSMutableArray *fakeData;
@end

@implementation MyViewController
@synthesize tableView = tableView;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [self.view addSubview:tableView];
    tableView.dataSource = self;
    tableView.delegate = self;
    
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"MJCell"];
    
    //集成刷新控件
    [self setupRefresh];
}

#pragma mark - 集成刷新控件
- (void)setupRefresh
{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    // [self.tableView addHeaderWithTarget:self action:@selector(headerRereshing)];
    // dateKey用于存储刷新时间,可以保证不同界面拥有不同的刷新时间
    [self.tableView addHeaderWithTarget:self action:@selector(headerRefreshing) dateKey:@"table"];//MJRefresh中的方法
    
#warning 自动刷新,已进入页面就刷新
    [self.tableView headerBeginRefreshing];//MJRefresh中的方法
    
    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [self.tableView addFooterWithTarget:self action:@selector(footerRefreshing)];//MJRefresh中的方法
    
    self.tableView.headerReleaseToRefreshText = @"下拉能刷新";
    self.tableView.headerRefreshingText = @"松开就刷新";
    self.tableView.headerRefreshingText = @"正在刷新";
    
    self.tableView.footerPullToRefreshText = @"上拉能刷新";
    self.tableView.footerReleaseToRefreshText = @"松开就刷新";
    self.tableView.footerRefreshingText = @"正在刷新";
}

#pragma mark - 获取数据
- (NSMutableArray *)fakeData
{
    if (!_fakeData) {
        _fakeData = [NSMutableArray array];
        
        for (int i = 0; i<10; i++) {
            [_fakeData addObject:RandomData];
        }
    }
    
    return _fakeData;
}

- (void)headerRefreshing
{
    //添加假数据
    for (int i = 0; i<10; i++) {
        [_fakeData insertObject:RandomData atIndex:0];
    }
    
    // 2.模拟2秒后刷新表格UI(真实开发中,可以移除这段gcd代码)
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(2.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        [self.tableView reloadData];
        NSLog(@"********************%@",self.fakeData);
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.tableView headerEndRefreshing];
    });
}
- (void)footerRefreshing
{
    //添加假数据
    for (int i; i<10; i++) {
        [_fakeData addObject:RandomData];
    }
    
    // 2.模拟2秒后刷新表格UI(真实开发中,可以移除这段gcd代码)
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(2.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        [self.tableView reloadData];
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.tableView footerEndRefreshing];
    });
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.fakeData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MJCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] init];
    }
    cell.textLabel.text = self.fakeData[indexPath.row];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LabVIEW是一种用于图形化编程的开发环境,用于控制、测量和数据获取,广泛应用于实验室、工程和科学领域。LabVIEW具有直观的用户界面和强大的数据处理功能,能够帮助用户快速开发和调试各种应用程序。 在LabVIEW实例练习是一种培训方式,通过实际操作一些案例来学习和掌握LabVIEW的应用。实例练习通常包括一个具体的问题或需求,并提供了相应的模板和教学材料,供学习者按照一定步骤进行操作和实践。 通过实例练习,学习者能够在实践逐步了解和运用LabVIEW的功能和特性。他们可以学会如何创建虚拟仪器、配置数据采集和控制系统以及进行数据处理和分析。实例练习还可以帮助学习者熟悉LabVIEW的编程语言和编辑器,并提供一些常见问题的解决方案。 实例练习的好处在于它能够让学习者通过实际操作来加深对理论知识的理解,并提供一个反馈机制,用于检查和纠正操作的错误。通过反复练习,学习者可以逐渐提高他们的技能和熟练度,从而能够更好地利用LabVIEW进行数据采集、实时控制和数据分析。 总之,LabVIEW的实例练习是一种以实践为核心的学习方式,通过实际操作来帮助学习者掌握LabVIEW的使用技巧和解决问题的能力。它是学习LabVIEW的重要方式之一,对于初学者来说尤为重要,能够帮助他们迅速上手并提高效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值