我在UITableView中使用多个单元格类型的代码在uitableview中使用多个单元格类型的问题
问题是单元格文本是不可见的。
代码:
static NSString *kCellIdentifier = @"NewsViewControllerTableCell";
static NSString *kCellIdentifier2 = @"SubscribeCell";
if ((indexPath.row==0) && ([[NSUserDefaults standardUserDefaults] boolForKey:@"subscribeButtonOption"]))
{
SubscribeCell* cell = (SubscribeCell*)[tableView dequeueReusableCellWithIdentifier:kCellIdentifier2];
if (cell == nil) {
cell = [[[SubscribeCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 35.0) reuseIdentifier:kCellIdentifier2] autorelease];
cell.contentView.backgroundColor = kColorR53G53B53;
cell.subscribeLabel.font = kLucidaSansStdFontBold_14;
cell.subscribeLabel.textColor = [UIColor whiteColor];
}
cell.subscribeLabel.textColor=[UIColor redColor];
cell.subscribeLabel.text = @"+ SUBSCRIBE TO NEWSLETTER";
cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cell.selectedBackgroundView.backgroundColor =kColorR53G53B53;
[cell setNeedsDisplay];
return cell;
}
else
{
//another cell
}
=========
头:
#import <UIKit/UIKit.h>
@interface SubscribeCell : UITableViewCell{
UILabel *subscribeLabel;
}
@property(nonatomic, retain) UILabel *subscribeLabel;
@end
为的cellForRowAtIndexPath以及细胞类代码的代码在下面给出而实现类:
#import "SubscribeCell.h"
@implementation SubscribeCell
@synthesize subscribeLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
subscribeLabel=[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 323.0, 40.0)];
subscribeLabel.textColor=[UIColor whiteColor];
self.backgroundColor=kColorR53G53B53;
}
return self;
}
和subscribeLabel不是IBOutlet中或不加入细胞作为子视图 – NeverBe 2012-02-10 20:52:28
良好的渔获物,错过了。 – 2012-02-10 20:59:13
嘿..固定它@NeverBe – Ahsan 2012-02-10 21:03:07