我正在根据附带的示例实现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时,如何初始化单元格?
答案 0 :(得分:1)
一般来说,从XIB加载视图时,不会初始化视图。你实际上会在你在UITableView中做的if(filledCell == nil)中做同样的事情(虽然使用AQGridViewCell而不是UITableViewCell)。因此,如果“GridCell.xib”将您的AQGridViewController作为文件所有者并且tempCell绑定到IB中的布局GridCell并且您已将标识设置为filledCellIdentifer,则可以执行以下操作:
[[NSBundle mainBundle] loadNibNamed:@"GridCell" owner:self options:nil];
filledCell = [self.tempCell autorelease];