【问题标题】:AQGridView: How to Init cellAQGridView:如何初始化单元格
【发布时间】:2011-07-01 15:28:46
【问题描述】:

我正在根据随附的示例实现 AQGridView。但我正在使用 xibs,在示例中,代码是:

 if ( plainCell == nil )
        {
            plainCell = [[[ImageDemoGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0)
                                                 reuseIdentifier: PlainCellIdentifier] autorelease];
            plainCell.selectionGlowColor = [UIColor blueColor];
        }

        plainCell.image = [UIImage imageNamed: [_imageNames objectAtIndex: index]];

        cell = plainCell;

    }

我的代码如下所示:

- (AQGridViewCell *) gridView: (AQGridView *)inGridView cellForItemAtIndex: (NSUInteger) index
  {


static NSString * FilledCellIdentifier = @"FilledCellIdentifier";

AQGridViewCell * cell = nil;

MagazineCell * filledCell = (MagazineCell *)[gridView dequeueReusableCellWithIdentifier: FilledCellIdentifier];

if ( filledCell == nil ) {


}

filledCell.edicaoLabel.text = [[data objectAtIndex:index] name];

cell = filledCell;

return ( cell );

}

示例 InitWith CGRect,但是当我使用 xibs 时如何初始化单元格?

【问题讨论】:

    标签: objective-c ipad grid aqgridview


    【解决方案1】:

    一般来说,从 XIB 加载视图时不会初始化视图。实际上,您会在 if (filledCell == nil) 中执行与在 UITableView 中执行的操作相同的操作(尽管使用 AQGridViewCell 而不是 UITableViewCell)。因此,如果“GridCell.xib”将您的 AQGridViewController 作为文件所有者,并且 tempCell 绑定到 IB 中布局的 GridCell,并且您已将标识符设置为filledCellIdentifer,您可以这样做:

    [[NSBundle mainBundle] loadNibNamed:@"GridCell" owner:self options:nil]; 
    filledCell = [self.tempCell autorelease];
    

    【讨论】: