AQGridView: How to Init cell
I'm implementing the AQGridView based on examples who comes with it. But I'm working with xibs, and in the example, the code is:
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;
}
My code looks like this:
- (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 );
}
The example InitWith CGRect, but how init the cell when I work with xibs?
Generally speaking, one doesn't init a view when loading it from XIB. You actually would do the same thing inside your if (filledCell == nil) that you would do in a UITableView (although with a AQGridViewCell instead of a UITableViewCell). So if "GridCell.xib" has your AQGridViewController as File Owner and tempCell is bound to the laid-out GridCell in IB and you've set the identifer to filledCellIdentifer, you can just do:
[[NSBundle mainBundle] loadNibNamed:@"GridCell" owner:self options:nil];
filledCell = [self.tempCell autorelease];
精彩评论