in carousel viewForItemAtIndex
i am using reuse view
something like this-
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
if (!view){
UIViewController * viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PopUpView"];
view = [viewController.view viewWithTag:1];
CGRect Frame = CGRectMake(view.frame.origin.x+300, view.frame.origin.y, view.frame.size.width+300, view.frame.size.height-350);
view.frame = Frame;
}
Is it a good approach?
I would say that this is not a good approach. You are creating a view controller here only to immediately throw it away, which is pointless.
If you just need the view, you can load it directly from a nib file without needing a view controller. You can bind it's actions to the main view controller for the carousel (there is an example of this in ControlsExample project included with the library), or create a custom view class and bind the subview outlets to the view itself.
If you want to use a view controller for each carousel item view (which I don't recommend, as this is not the convention used for UITableView or UICollectionView, which iCarousel is modelled on) then you should add the view controller as a child view controller of the main carousel controller, but this is fiddly as there is no obvious place where you can remove the child controller again when its view goes offscreen).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With