从XIB加载AQGridViewCell(不工作)

我正在使用
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 );
}
    
已邀请:
这篇文章描述了如何使用示例代码从nib加载AQGridViewCell。查看名为“可重用的AQGridViewCell”的部分。 (感谢pt2ph8指出
contentView
。)     
根据我的理解,我认为它显示为空白,因为显示的是单元格的
contentView
。我最终从IB加载我的自定义视图,并在请求单元格时将其添加为单元格的sub3ѭ的子视图。 AQGridView的开发人员曾在GitHub上声称将来会添加适当的IB支持,但该帖子的日期是2010年8月,所以不要屏住呼吸。     
这花了我一段时间,但我认为与jlstrecker提到的博客文章不同。 创建一个
AQGridViewCell
的子类 - 让我们调用它
MyGridViewCell
。 为该单元格创建一个笔尖,在IB中将其链接起来。 在IB中查看单元格视图的顶部视图。这是正确的,一种观点 在视图之上。使大小完全相同。 对于那个观点 在视图的顶部(我们称之为
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;
}
请享用!     
我不熟悉AQGridView,但我相信你可以利用NSBundle的Nib加载功能。 AdvancedTableViewCells示例项目的摘录说明了这个想法: RootViewController.h
@interface RootViewController : UITableViewController
{
    ApplicationCell *tmpCell;
}
RootViewController.m
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
    [[NSBundle mainBundle] loadNibNamed:@"IndividualSubviewsBasedApplicationCell" owner:self options:nil];
    cell = tmpCell;
    self.tmpCell = nil;
}
在IndividualSubviewsBasedApplicationCell.xib中,您必须将UITableViewCell的出口设置为RootViewController的tmpCell属性。然后,作为调用NSBundle的loadNibNamed方法的副作用,通过Nib加载机制在RootViewController上设置tmpCell属性。     
您可以做的是在子类本身中执行xib(uiview)解包/加载(它具有与uitableviewcell不同的init方法) 您还可以将任何插座连接到此xib,并将其整个视图添加为子视图,或者可以替换contentview)。 为了使它更快,你可以制作这个xib的uinib并重复使用它来节省磁盘i / o。     
使用IB正常构建您的单元格,然后在您的AQGridViewCell的子类中添加
- (void)awakeFromNib{
    self.contentView.backgroundColor = [UIColor clearColor];
}
    

要回复问题请先登录注册