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

其他提示

As per approach, there is nothing wrong in using a view controller's view. UIView is where you handle what it looks like, UIViewController is the class where you handle events. If you want to handle any events then using UIViewController's View is a better option.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top