Guest User

Untitled

a guest
Aug 15th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #import "MTResultsViewController.h"
  2. #import "MTGetResults.h"
  3. #import "NSDictionary+sortedKeys.h"
  4. #import "MTResultsCell.h"
  5. #import "MTResultCard.h"
  6. #import "MTDataLayer.h"
  7.  
  8. @interface MTResultsViewController ()
  9.  
  10. @property NSString *tab;
  11. @property int etapa;
  12. @property (nonatomic, strong) NSMutableArray *viewControllers;
  13.  
  14. @end
  15.  
  16. @implementation MTResultsViewController
  17. //@synthesize tableView, swipeView, pageControl;
  18.  
  19. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  20. {
  21. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  22. if (self) {
  23. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateResults) name:@"resultsUpdate" object:nil];
  24. [MTGetResults getResults];
  25. }
  26. return self;
  27. }
  28.  
  29. - (void)viewDidLoad
  30. {
  31. [super viewDidLoad];
  32.  
  33. //configure swipe view
  34. _swipeView.alignment = SwipeViewAlignmentCenter;
  35. _swipeView.pagingEnabled = YES;
  36. _swipeView.wrapEnabled = NO;
  37. _swipeView.itemsPerPage = 1;
  38. _swipeView.truncateFinalPage = YES;
  39.  
  40. //configure page control
  41. _pageControl.defersCurrentPageDisplay = YES;
  42.  
  43. // Uncomment the following line to preserve selection between presentations.
  44. // self.clearsSelectionOnViewWillAppear = NO;
  45.  
  46. // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  47. // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  48. [super setViewTitle:@"Screen title];
  49. }
  50.  
  51. -(void)updateResults{
  52. [_swipeView reloadData];
  53. _pageControl.numberOfPages = _swipeView.numberOfPages;
  54. }
  55.  
  56. - (NSInteger)numberOfItemsInSwipeView:(SwipeView *)swipeView
  57. {
  58. // Get the count of the current tab
  59. NSDictionary *resultsDictionary = [[MTDataLayer sharedDataLayer].results objectForKey:@"mykey"];
  60.  
  61. return [resultsDictionary count];
  62. }
  63.  
  64. - (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
  65. {
  66. view = [[MTResultCard alloc] initWithFrame:_swipeView.frame];
  67.  
  68. NSDictionary *resultsDictionary = [[MTDataLayer sharedDataLayer].results objectForKey:@"mykey"];
  69.  
  70. NSString *key = [[[[MTDataLayer sharedDataLayer].results objectForKey:@"mykey"] allKeysSorted] objectAtIndex:index];
  71. // view.item = [[[[MTDataLayer sharedDataLayer].results objectForKey:@"mykey"] objectForKey:key] objectAtIndex:index];
  72. ((MTResultCard *)view).item = [[[MTDataLayer sharedDataLayer].results objectForKey:@"mykey"] objectForKey:key];
  73.  
  74. return view;
  75. }
  76.  
  77. - (void)swipeViewCurrentItemIndexDidChange:(SwipeView *)swipeView
  78. {
  79. //update page control page
  80. _pageControl.currentPage = swipeView.currentPage;
  81. }
  82.  
  83. - (void)swipeView:(SwipeView *)swipeView didSelectItemAtIndex:(NSInteger)index
  84. {
  85. // NSLog(@"Selected item at index %i", index);
  86. }
  87.  
  88. - (IBAction)pageControlTapped
  89. {
  90. //update swipe view page
  91. [_swipeView scrollToPage:_pageControl.currentPage duration:0.4];
  92. }
  93.  
  94. - (IBAction)campionat:(id)sender {
  95.  
  96. [[NSNotificationCenter defaultCenter]postNotificationName:@"championshipUpdate" object:nil];
  97. }
  98. - (IBAction)cupa:(id)sender {
  99.  
  100. [[NSNotificationCenter defaultCenter]postNotificationName:@"coupeUpdate" object:nil];
  101. }
  102.  
  103. - (void)didReceiveMemoryWarning
  104. {
  105. [super didReceiveMemoryWarning];
  106. // Dispose of any resources that can be recreated.
  107. }
  108.  
  109. - (void)viewDidUnload {
  110. [self setPageControl:nil];
  111. [super viewDidUnload];
  112. }
  113. @end
Advertisement
Add Comment
Please, Sign In to add comment