从 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 );
}
I am using AQGridView
class and I am trying to load a cell from an XIB. I have setup the XIB like a Custom Cell for a UITableView
, but when I attempt to load the cell, it is simply blank. I was wondering if there was an easier way to get the XIB to load.
AQGridViewCell need to load the cell from an 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 );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这里有一篇文章,介绍了如何从 nib 加载 AQGridViewCell 以及示例代码。查看名为“可重用的 AQGridViewCell”的部分。
(感谢 pt2ph8 指出
contentView
。)Here's an article that describes how to load an AQGridViewCell from nib, with example code. Check out the section called "A reusable AQGridViewCell".
(Thanks to pt2ph8 for pointing out
contentView
.)据我了解,我认为它显示为空白,因为显示的是单元格的
contentView
。我最终从 IB 加载了自定义视图,并在请求单元格时将其添加为单元格contentView
的子视图。AQGridView 的开发人员曾在 GitHub 上声称将来会添加适当的 IB 支持,但该帖子的日期是 2010 年 8 月,所以不要屏住呼吸。
From what I've understood, I think it shows as blank because what gets displayed is the cell's
contentView
. I ended up loading my custom view from IB and adding it as a subview of the cell'scontentView
when the cell is requested.AQGridView's developers once claimed on GitHub that proper IB support will be added in the future, but that post is dated August 2010, so don't hold your breath.
这花了我一段时间,但我想出了一种与博客文章 jlstrecker 提到的不同的方法。
AQGridViewCell
的子类 - 我们称之为MyGridViewCell
。在视图之上。使尺寸完全相同。
在视图的顶部(我们称之为
view2
),设置tag
属性(可以在IB中完成)到1.
view2
,装饰你的单元格,无论你想要什么。AQGridViewController
的子类中使用以下代码(当然,根据您的需要进行更改):`
Enjoy!
This took me a while, but I figured a different way than the blog post jlstrecker mentioned.
AQGridViewCell
- let's call itMyGridViewCell
.on top of a view. Make the size the exact same.
top of the view (let's call it
view2
), set thetag
property (canbe done in IB) to 1.
view2
, decorate your cell, whatever you'd like.AQGridViewController
:`
Enjoy!
我对 AQGridView 不熟悉,但我相信您可以利用 NSBundle 的 Nib 加载功能。 AdvancedTableViewCells 示例项目的摘录说明了这个想法:
RootViewController.h
RootViewController.m
在IndividualSubviewsBasedApplicationCell.xib 内部,您必须将UITableViewCell 的出口设置为RootViewController 的tmpCell 属性。然后,作为调用 NSBundle 的 loadNibNamed 方法的副作用,tmpCell 属性通过 Nib 加载机制在 RootViewController 上设置。
I'm not familiar with AQGridView, but I believe you can leverage NSBundle's Nib loading capabilities. An excerpt from AdvancedTableViewCells sample project illustrates the idea:
RootViewController.h
RootViewController.m
Inside the IndividualSubviewsBasedApplicationCell.xib you would have to set the outlet of the UITableViewCell within to be the RootViewController's tmpCell property. Then, as a side effect of invoking NSBundle's loadNibNamed method, the tmpCell property gets set on the RootViewController via the Nib loading mechanism.
您可以做的是在子类本身中进行 xib (uiview) 解包/加载(它确实具有与 uitableviewcell 不同的 init 方法)
您还可以将任何插座连接到此 xib 并将其整个视图添加为子视图,或者替换 contentview)。
为了使其更快,您可以将此 xib 制作为 uinib 并重用它来节省磁盘 I/O。
What you can do is do your xib (uiview) unpacking/loading in the subclass itself (which does have a different init method than a uitableviewcell)
you can also connect any outlets to this xib and add its entire view as a subview, or maybe replace contentview).
To make it even faster you can make uinib of this xib and reuse it to save disk i/o.
通常使用 IB 构建单元格,然后在 AQGridViewCell 的子类中添加
Build your cell normally using IB, then in your subclass of AQGridViewCell, add