此刻,我有以下類:自定義單元格是永遠爲零(不使用故事板)
我的問題是,我的自定義單元格類「GTNewsCustomCell」永遠不會被調用,我設置一些斷點在.m文件中,但沒有任何事情發生,比我意識到,在我的「cellForRowAtIndexPath」單元格從來沒有零!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier1 = @"NewsCell";
GTNewsCustomCell *newsCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if(newsCell == nil){
newsCell = [[GTNewsCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
}
newsCell.titleLabel.text = [[self.newsList objectAtIndex:indexPath.section]objectForKey:@"title"];
NSAttributedString *attString = [[NSAttributedString alloc]initWithString:[[self.newsList objectAtIndex:indexPath.section]objectForKey:@"previewMessage"]];
newsCell.messageTextView.attributedText = attString;
return newsCell;
}
這裏是從我的GTNewsCustomCell.m我的代碼的一小部分:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.messageTextView.textColor = [UIColor blackColor];
self.messageTextView.backgroundColor = GTDefaultTextBackgroundColor;
self.messageTextView.editable = NO;
self.messageTextView.userInteractionEnabled = NO;
self.messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
NSString *htmlTag = @"<b></b>";
NSString *html = [NSString stringWithFormat:@"%@%@",htmlTag,self.messageTextView.attributedText];
NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];
CGFloat fontSizeMultiplier = 1.1;
CGFloat const DTCoreTextDefaultFontSize = 12.0;
NSString * fontName = @"Helvetica";
DTCSSStylesheet* css;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){
css = [[DTCSSStylesheet alloc] initWithStyleBlock:@"ul li{padding-left: -10px;}"];
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:fontSizeMultiplier], NSTextSizeMultiplierDocumentOption,
fontName, DTDefaultFontFamily,
@"purple", DTDefaultLinkColor,
@"red", DTDefaultLinkHighlightColor,
css,DTDefaultStyleSheet,
[NSNumber numberWithBool:YES],DTUseiOS6Attributes,
nil];
.
.
.
.
下面是我的廈門國際銀行文件的一些截圖的詳細資料:
我的GTNewsTableViewController:
GTNewsCustomCell(FilesOwner):
GTNewsCustomCell(查看):
GTNewsCustomCell:
如果你在這樣'你的表視圖註冊您的電池可能會發生這種[:[UINib nibWithNibName:_tableView registerNib @ 「CellXib」 捆綁:無] forCellReuseIdentifier:@ 「標識」];'。如果你這樣做,嘗試把所有樣式放在表格單元的-awakeFromNib方法中 – Eugene
是的,我做UINib * nib = [UINib nibWithNibName:@「GTNewsCustomCell」bundle:nil]; [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier1];我會測試它.... – Davis