-1

I have a a custom UITableViewCell class and in it I have a UIImageView. This UIImageView is only displayed when the text of the UITableViewCell is equal to a certain string, eg "Home". When the method mapView:regionWillChangeAnimated: is called, I want to apply an animation on this UIImageView.

My question is how can I, when mapView:regionWillChangeAnimated: is called, go through my UITableView and custom UITableViewCells and perform an animation on the UIImageView within the cells which have the UIImageView set as visible?

I've been able to call methods on cells before using the UITableView delegate methods but I'm struggling to find a solution in this scenario because the the UITableView is not being directly called by the map panning method, it's not a didSelectRowAtIndex path issue?

Thank you.

2 Answers 2

0

If you have reference to table view in your map delegate method, you can get all visible cells using visibleCells method in UITableView and apply animation for them if needed. General structure may look like:

// Controller
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
  ...
  [self applyCellsAnimation];
}

- (void)applyCellsAnimation {
   for (CustomCell* cell in [self.tableView visibleCells]) {
      [cell performImageAnimationIfNeeded];
   }
}

// CustomCell
- (void)performImageAnimationIfNeeded {
   if (!self.myImageView.hidden) { 
      // perform animation
   }
}
1
  • Thanks @Vladimir, I'll look into this solution today!
    – afcgold
    Oct 23, 2014 at 11:22
0

You can get an array of all the visible rows in your table view using [myTableView visibleCells]

You then just need to integrate through each cell and animate the image. i.e.

for (MyCustomCell* cell  in [myTableView visibleCells])
{
 [cell animateImage];
}

The implementation of animateImage can then do whatever you want - just check the imageView.hidden property and animate it if the imageView is visible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.