【发布时间】:2009-11-13 14:37:28
【问题描述】:
我创建了一个非常简单的应用程序,我试图在表格视图中插入一个自定义单元格。但是,每当我返回自定义单元格的实例时,屏幕上什么都不会显示,其次,应用程序会进入某种奇怪的无限循环。任何帮助将非常感激。我在这个问题中附上了我的代码。
-- view controller which is returning custom cells ---
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Try to recover a cell from the table view with the given identifier, this is for performance
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
// If no cell is available, create a new one using the given identifier
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle]
loadNibNamed:@"sample_1ViewController" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[CustomCell class]])
{
cell = currentObject;
break;
}
}
}
// Fill the cell
cell.lbl.text = @"test";
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
}
--- custom cell class ---
@interface CustomCell : UITableViewCell {
IBOutlet UILabel * lbl;
}
@property (nonatomic, retain) IBOutlet UILabel * lbl;
@end
@implementation CustomCell
@synthesize lbl;
@end
----
自定义单元格是 sample_1ViewController.xib 文件中的 UITableCellView 资源。它包含一个 UILabel。 CustomCell 的标识符也是 CustomCell。
请看看你是否能找到可能有问题的地方,或者告诉我我可能遗漏的地方。
问候 尼丁
【问题讨论】:
-
无限循环的堆栈跟踪是什么?
标签: iphone