1

我查看了以下链接中的代码:

为什么我的原型单元格显示为空白?

以及 www.techtopia.com 上使用自定义表格视图原型的教程: http ://www.techotopia.com/index.php/Using_Xcode_Storyboards_to_Build_Dynamic_TableViews_with_Prototype_Table_View_Cells

但是我仍然让我的根视图显示为空白。

我已经设置了记录从我的 XML 解析器委托接收数据的方法,并且我知道数据正在进入,但由于某种原因,除非我使用默认样式之一(字幕等),否则我无法使用我自己构建的自定义原型。

这是我的示例代码:

对于自定义 UITableViewCell 类 (TickerListViewCell.h):

#import "TickerListViewCell.h"

@implementation TickerListViewCell

@synthesize ticker = _ticker;
@synthesize companyName = _companyName;
@synthesize price = _price;

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

@end

(TickerListViewCell.m)

#import <UIKit/UIKit.h>

@interface TickerListViewCell : UITableViewCell

@property (nonatomic, strong) IBOutlet UILabel *ticker;
@property (nonatomic, strong) IBOutlet UILabel *companyName;
@property (nonatomic, strong) IBOutlet UILabel *price;


@end

(TickerListViewController.m) ...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomStockCell";

TickerListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
    cell = [[TickerListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomStockCell"];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

// Configure the cell...

self.currentStock = [self.mystocks objectAtIndex:[indexPath row]];

cell.ticker.text = self.currentStock.symbol;
cell.companyName.text = self.currentStock.companyName;
cell.price.text = [self.currentStock.askRealtime stringValue];

NSLog(@"Configured cell for stock: %@",[(Stock *)[self.mystocks objectAtIndex:[indexPath row]] symbol]);
return cell;
}

...

我相信问题发生在对“cellForRowAtIndexPath”的调用中,因为当我将原型更改为通用字幕时,它可以工作,但是我的自定义原型失败了。请记住,我还确保原型单元的类已映射到我的自定义类。

正如一些教程所指出的那样,我已经尝试取出“if(cell == nil)”块,但这并没有解决问题。该代码在预编译时没有显示任何错误,但是一旦我尝试在没有该块的 iOS 6 模拟器中运行它,就会生成一个错误。

任何帮助表示赞赏。我现在已经无计可施了。

4

0 回答 0