通用字幕原型样式有效但自定义原型没有

时间:2012-11-01 00:50:32

标签: objective-c

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

Why do my prototype cells show up blank?

以及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模拟器中运行它,就会生成一个错误。

感谢任何帮助。我现在已经知道了。

0 个答案:

没有答案
相关问题