In my code i was trying to set label in iCarouselView.My icarousel contains labels and textView so i am trying to set label but it is not setting properly.I have array of months and setting that array of months to each icarousel label, like this.

     (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
    {
       if (!view)
   {
         UIViewController * viewController = [self.storyboard  instantiateViewControllerWithIdentifier:@"PopUpView"];
    view = [viewController.view viewWithTag:999];
     UILabel *label=(UILabel*)[viewController.view viewWithTag:109];
   label.text = [_monthsArray objectAtIndex:index];
   CGRect  Frame = CGRectMake(view.frame.origin.x, view.frame.origin.y+100, view.frame.size.width, view.frame.size.height);
    view.frame = Frame;
}
return view;}

I am loading external view as popUpView in storyBoard and getting label using tag. And i am returning carousel count as [monthsArray count]. carousel delegate and datasource is also set and reloadData method is also called on iCarousel.

The output which i am getting is something like this.

| January,February,March,November,December|

Please tell me where i am wrong?and what to do now?

有帮助吗?

解决方案

Update you code to below one -

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    if (!view){
        UIViewController * viewController = [self.storyboard  instantiateViewControllerWithIdentifier:@"PopUpView"];
        view = [viewController.view viewWithTag:999];
        CGRect  Frame = CGRectMake(view.frame.origin.x, view.frame.origin.y+100, view.frame.size.width, view.frame.size.height);
        view.frame = Frame;
    }

    UILabel *label=(UILabel*)[view viewWithTag:109];
    label.text = [_monthsArray objectAtIndex:index];

    return view;
}

iCaurosel will take UIView, In your case you are creating a view controller, which is not retained and is dangerous. See if you change it to view via a custom Xib.

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