Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. ActivityCell.h
  2. @interface ActivityCell : UITableViewCell
  3. @property (strong, nonatomic) IBOutlet UILabel *studentNameLabel;
  4. @property (strong, nonatomic) IBOutlet UIProgressView *progressView;
  5.  
  6. @implementation tchLessonActivityTVC
  7. #define debug 1
  8.  
  9. - (IBAction)incrementActivity:(id)sender {
  10.  
  11. NSLog(@"increment");
  12. }
  13. - (IBAction)decrementActivity:(id)sender {
  14. NSLog(@"decrement");
  15. }
  16.  
  17. -(void)fetchData{
  18. CoreDataHelper *cdh = [(AppDelegate*)[[UIApplication sharedApplication]delegate]cdh];
  19. SchoolClass *schoolClass = (SchoolClass*)[cdh.context existingObjectWithID:[IDsManager getClassID] error:nil];
  20. Lesson *lesson = (Lesson*)[cdh.context existingObjectWithID:[IDsManager getLessonID] error:nil];
  21.  
  22. if (lesson.activities.count == 0) {
  23. for (Student *student in schoolClass.students) {
  24. Activity *activity = [NSEntityDescription insertNewObjectForEntityForName:@"Activity" inManagedObjectContext:cdh.context];
  25. activity.student = student;
  26. activity.lesson = lesson;
  27. [lesson addActivitiesObject:activity];
  28. [student addActivitiesObject:activity];
  29. }
  30. }
  31. self.activities = [NSArray arrayWithArray:[lesson.activities allObjects]];
  32. }
  33.  
  34. - (void)viewDidLoad
  35. {
  36. [super viewDidLoad];
  37. self.tableView.delegate = self;
  38. [self fetchData];
  39. }
  40.  
  41. #pragma mark - Table view data source
  42.  
  43. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  44. {
  45. return 1;
  46. }
  47.  
  48. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  49. {
  50. return self.activities.count;
  51. }
  52.  
  53. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  54. {
  55. if(debug == 1){
  56. NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd));
  57. }
  58.  
  59. static NSString *cellIndetifier = @"Activity Cell";
  60. ActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndetifier
  61. forIndexPath:indexPath];
  62.  
  63. Activity *activity = [self.activities objectAtIndex:indexPath.row];
  64.  
  65. cell.studentNameLabel.text = activity.student.name;
  66. CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 5.0f);
  67. cell.progressView.transform = transform;
  68.  
  69. cell.progressView.progress = 0.32f;
  70. return cell;
  71. }
  72.  
  73. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. NSLog(@"selected index is %d",indexPath.row);
  76. }
  77. @end
  78.  
  79. tableView.delegate = self;
  80.  
  81. @protocol TableViewCellDelegate <NSObject>
  82.  
  83. - (void)requestToReloadTableViewFromCell:(UITableViewCell *)cell;
  84.  
  85. @end
  86.  
  87. @interface TableViewCell : UITableViewCell
  88.  
  89. @property (weak, nonatomic) IBOutlet UILabel *dateLabel;
  90. @property (weak, nonatomic) id <TableViewCellDelegate> cellDelegate;
  91.  
  92. @end
  93.  
  94. - (IBAction)buttonAction:(UIButton *)sender
  95. {
  96. [self.cellDelegate requestToReloadTableViewFromCell:self];
  97. }
  98.  
  99. @interface TableViewController () <TableViewCellDelegate>
  100.  
  101. @end
  102.  
  103. @implementation TableViewController
  104.  
  105. - (void)requestToReloadTableViewFromCell:(UITableViewCell *)cell
  106. {
  107. NSLog(@"%d", [[self.tableView indexPathForCell:cell] row]);
  108. [self.tableView reloadData];
  109. }
  110.  
  111.  
  112. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
  115.  
  116. // Configure the cell...
  117. cell.cellDelegate = self;
  118. cell.dateLabel.text = [[NSDate date] description];
  119.  
  120. return cell;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement