0

Hello all,

I have to add one more view in cell of GMGridView. But i am unable to do this because i have to drag my label from view to view1.

My code is :

- (GMGridViewCell *)GMGridView:(GMGridView *)gridView1 cellForItemAtIndex:(NSInteger)index
        {
        // set size based on orientation

        CGSize size = [self GMGridView:gridView sizeForItemsInInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
        GMGridViewCell *cell = [gridView dequeueReusableCell];
        if (!cell)
        {
                cell = [[[GMGridViewCell alloc]init]autorelease];

//one view
                UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
                view.backgroundColor = [UIColor redColor];
                view.layer.masksToBounds = NO;
                view.layer.cornerRadius = 2;
                cell.contentView = view;

//another view
            UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 80, size.width, size.height)];
            view1.backgroundColor = [UIColor yellowColor];
            view1.layer.masksToBounds = NO;
            view1.layer.cornerRadius = 2;
            cell.contentView = view1;
        }
        [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

        // allocate label
        UILabel *label = [[UILabel alloc] initWithFrame:cell.contentView.bounds];
        label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        label.text = (NSString *)[self.currentData objectAtIndex:index];
        label.textAlignment = UITextAlignmentCenter;
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont boldSystemFontOfSize:20];
        [cell.contentView addSubview:label];
        return cell;
    }

height of cell is 200. but still it shows only one view.

Ankur
  • 5,086
  • 19
  • 37
  • 62
Abha
  • 1,032
  • 1
  • 13
  • 36

1 Answers1

0

Loading Two types of Cell in GMGridView

This is your Solution, it works as charm..

First Do this Exactly

-(void)prepareExhibitor
{
    NSInteger spacing = 1.0;
    CGRect rect=self.view.frame;
    rect.origin=CGPointMake(0, 0);
    self.gmGridView = [[GMGridView alloc] initWithFrame:rect];
    self.gmGridView.backgroundColor = [UIColor clearColor];
    self.gmGridView.centerGrid=NO;

self.gmGridView.style = GMGridViewStylePush;

self.gmGridView.layoutStrategy = [GMGridViewLayoutStrategyFactory strategyFromType:GMGridViewLayoutHorizontal];

self.gmGridView.showsHorizontalScrollIndicator=FALSE;
self.gmGridView.clipsToBounds=YES;
self.gmGridView.itemSpacing = spacing;
self.gmGridView.minEdgeInsets = UIEdgeInsetsMake(0,30, 0, 0);
[self.viewNewsHeadline addSubview:self.gmGridView];
self.gmGridView.actionDelegate = self;
self.gmGridView.dataSource = self;
self.gmGridView.mainSuperView = self.superView;

}

Then Write this accordingly as per your Code

- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index
{


    GMGridViewCell *cell = [gridView dequeueReusableCell];
    NewsCell_iPad *view;
    UIViewController *controller;


    if (!cell)
    {

        // [self removeGrid];
        cell = [[GMGridViewCell alloc] init];
        if(index%2==0)
        {
            controller=[[UIViewController alloc] initWithNibName:@"NewsCellTypeA_iPad" bundle:nil];
        }
        else
        {
            controller=[[UIViewController alloc] initWithNibName:@"NewsCellTypeB_iPad" bundle:nil];
        }
        if(!view)
        {
            view=(NewsCell_iPad *)controller.view;
        }

        cell.layer.masksToBounds = NO;
        cell.contentView = view;
    }


    NewsCell_iPad *newsView=(NewsCell_iPad *)cell.contentView;
        newsView.news=[self.arrNews objectAtIndex:index];
      [self hideGradientBackground:newsView.webViewDetailedNews];
    [newsView downloadImage];
    [newsView loadWebView];
   // NSLog(@"cell=%d ,arr image index=%@",index,[self.arrNews objectAtIndex:index]);


    return cell;
}
Vizllx
  • 9,135
  • 1
  • 41
  • 79