0

大家好,

我必须在GMGridView. 但我无法做到这一点,因为我必须将我的标签从视图拖到view1.

我的代码是:

- (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;
    }

单元格的高度为 200。但它仍然只显示一个视图。

4

1 回答 1

0

在 GMGridView 中加载两种类型的 Cell

这是您的解决方案,它具有魅力..

首先做到这一点

-(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;

}

然后根据您的代码相应地编写

- (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;
}
于 2013-10-05T13:55:36.763 回答