MJSingleViewController.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // MJSingleViewController.m
  3. // MJRefreshExample
  4. //
  5. // Created by MJ Lee on 15/6/13.
  6. // Copyright © 2015年 小码哥. All rights reserved.
  7. //
  8. #import "MJSingleViewController.h"
  9. #import "MJTestViewController.h"
  10. #import "MJRefresh.h"
  11. @interface MJSingleViewController ()
  12. @property (assign, nonatomic) int count;
  13. @end
  14. @implementation MJSingleViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.count = 0;
  18. __weak typeof(self) weakSelf = self;
  19. __weak UITableView *tableView = self.tableView;
  20. tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  21. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  22. weakSelf.count += 12;
  23. [tableView reloadData];
  24. [tableView.header endRefreshing];
  25. });
  26. }];
  27. tableView.header.automaticallyChangeAlpha = YES;
  28. MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  29. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  30. weakSelf.count += 5;
  31. [tableView reloadData];
  32. [tableView.footer endRefreshing];
  33. });
  34. }];
  35. footer.hidden = YES;
  36. tableView.footer = footer;
  37. }
  38. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  39. {
  40. return self.count;
  41. }
  42. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  43. {
  44. static NSString *ID = @"cell";
  45. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  46. if (cell == nil) {
  47. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
  48. }
  49. if (indexPath.row % 2 && self.navigationController) {
  50. cell.textLabel.text = @"push";
  51. } else {
  52. cell.textLabel.text = @"modal";
  53. }
  54. return cell;
  55. }
  56. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  57. {
  58. MJTestViewController *test = [[MJTestViewController alloc] init];
  59. if (indexPath.row % 2 && self.navigationController) {
  60. test.hidesBottomBarWhenPushed = YES;
  61. [self.navigationController pushViewController:test animated:YES];
  62. } else {
  63. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:test];
  64. [self presentViewController:nav animated:YES completion:nil];
  65. }
  66. }
  67. @end