2011-07-01 49 views
1

我正在实现AQGridView的基础上,它附带的例子。但我有xibs工作,并在本例中,代码:AQGridView:如何初始化单元格

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时单元格?

回答

1

一般来说,从XIB加载它时不会初始化视图。你实际上会在你的if(filledCell == nil)中做同样的事情,你会在UITableView中做的(尽管用AQGridViewCell而不是UITableViewCell)。所以,如果“GridCell.xib”有你AQGridViewController作为文件所有者和tempCell被绑定到IB的布局的栅格单元,并且已经设置了IDENTIFER到filledCellIdentifer,你可以做:

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