Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it good to use ViewCntroller's view in icarousel?

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?

like image 345
Saheb Singh Avatar asked Apr 21 '14 06:04

Saheb Singh


1 Answers

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).

like image 69
Nick Lockwood Avatar answered Sep 18 '22 03:09

Nick Lockwood