我使用AQGridView类,并试图从XIB加载一个单元格。我已经将XIB设置为UITableView的自定义单元格,但是当我试图加载该单元格时,它只是空的。我想知道是否有更容易的方法来加载XIB。
AQGridViewCell需要从xib加载单元格。
- (AQGridViewCell *) gridView: (AQGridView *) gridView cellForItemAtIndex: (NSUInteger) index
{
static NSString * CellIdentifier = @"cellID";
gridCell * cell = (gridCell *)[gridView dequeueReusableCellWithIdentifier: CellIdentifier];
if ( cell == nil ){
gridCell = [[gridViewCell alloc] initWithFrame: CGRectMake(0,0,_gridView.frame.size.width/2-4,
_gridView.frame.size.height/2-8)
reuseIdentifier:CellIdentifier];
cell = gridCell;
self.gridCell = nil;
}
cell.title = @"Test Grid Item";
cell.date = @"Apr. 7, 2011";
return ( cell );
}发布于 2011-10-31 14:42:51
这是一篇文章,描述如何从nib加载AQGridViewCell,并给出了示例代码。请查看名为“一个可重用的AQGridViewCell”的部分。
(感谢pt2ph8指出contentView。)
发布于 2011-04-21 11:04:55
据我所知,我认为它显示为空白,因为所显示的是单元格的contentView。最后,我从IB加载自定义视图,并在请求单元格时将其添加为单元格的contentView的子视图。
AQGridView的开发者曾经在GitHub上声称将来会添加适当的IB支持,但是这篇文章的日期是2010年8月,所以不要屏住呼吸。
发布于 2012-06-25 21:32:53
这花了我一段时间,但我想出了一种与jlstrecker提到的博客文章不同的方式。
AQGridViewCell的子类--让我们称之为MyGridViewCell。view2),将tag属性(可以在IB中完成)设置为1。view2上面,装饰你的手机,任何你想要的。AQGridViewController子类中使用以下代码(当然,将其更改为您的需要)`
- (AQGridViewCell *)gridView:(AQGridView *)aGridView cellForItemAtIndex:(NSUInteger)index {
static NSString *CellIdentifier = @"MyGridViewCell";
MyGridViewCell *cell = (MyGridViewCell *)[self.gridView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = (ZZProductGridViewCell *)[[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0];
}
[cell.contentView addSubview:[cell viewWithTag:1]]; //THIS IS THE IMPORTANT PART
return cell;
}享受吧!
https://stackoverflow.com/questions/5589575
复制相似问题