Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ActivityCell.h
- @interface ActivityCell : UITableViewCell
- @property (strong, nonatomic) IBOutlet UILabel *studentNameLabel;
- @property (strong, nonatomic) IBOutlet UIProgressView *progressView;
- @implementation tchLessonActivityTVC
- #define debug 1
- - (IBAction)incrementActivity:(id)sender {
- NSLog(@"increment");
- }
- - (IBAction)decrementActivity:(id)sender {
- NSLog(@"decrement");
- }
- -(void)fetchData{
- CoreDataHelper *cdh = [(AppDelegate*)[[UIApplication sharedApplication]delegate]cdh];
- SchoolClass *schoolClass = (SchoolClass*)[cdh.context existingObjectWithID:[IDsManager getClassID] error:nil];
- Lesson *lesson = (Lesson*)[cdh.context existingObjectWithID:[IDsManager getLessonID] error:nil];
- if (lesson.activities.count == 0) {
- for (Student *student in schoolClass.students) {
- Activity *activity = [NSEntityDescription insertNewObjectForEntityForName:@"Activity" inManagedObjectContext:cdh.context];
- activity.student = student;
- activity.lesson = lesson;
- [lesson addActivitiesObject:activity];
- [student addActivitiesObject:activity];
- }
- }
- self.activities = [NSArray arrayWithArray:[lesson.activities allObjects]];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.tableView.delegate = self;
- [self fetchData];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.activities.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if(debug == 1){
- NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd));
- }
- static NSString *cellIndetifier = @"Activity Cell";
- ActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndetifier
- forIndexPath:indexPath];
- Activity *activity = [self.activities objectAtIndex:indexPath.row];
- cell.studentNameLabel.text = activity.student.name;
- CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 5.0f);
- cell.progressView.transform = transform;
- cell.progressView.progress = 0.32f;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSLog(@"selected index is %d",indexPath.row);
- }
- @end
- tableView.delegate = self;
- @protocol TableViewCellDelegate <NSObject>
- - (void)requestToReloadTableViewFromCell:(UITableViewCell *)cell;
- @end
- @interface TableViewCell : UITableViewCell
- @property (weak, nonatomic) IBOutlet UILabel *dateLabel;
- @property (weak, nonatomic) id <TableViewCellDelegate> cellDelegate;
- @end
- - (IBAction)buttonAction:(UIButton *)sender
- {
- [self.cellDelegate requestToReloadTableViewFromCell:self];
- }
- @interface TableViewController () <TableViewCellDelegate>
- @end
- @implementation TableViewController
- - (void)requestToReloadTableViewFromCell:(UITableViewCell *)cell
- {
- NSLog(@"%d", [[self.tableView indexPathForCell:cell] row]);
- [self.tableView reloadData];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
- // Configure the cell...
- cell.cellDelegate = self;
- cell.dateLabel.text = [[NSDate date] description];
- return cell;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement