UITableViewCell显示图像但不显示文本

时间:2013-10-06 06:30:10

标签: ios objective-c uitableview uiimageview

我有一个自定义UITableViewCell,其中包含UIImageView和两个UILabel。当我运行应用时,UIImageVIew显示但不显示UILabel

这是我的代码:

ViewController.m

-(void)viewDidLoad
 {
     [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    self.myTableView.dataSource = self;
    self.myTableView.delegate = self;

   titleLabel = @[@"Kiruba",@"Kiruba",@"Kiruba",@"Kiruba"];
   subtitleLabel = @[@"xxx",@"xxx",@"CHN",@"CHN"];
 }

-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return titleLabel.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *cellId = @"Cell";
     CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    //  NSLog(@"Text : %@",[titleLabel objectAtIndex:indexPath.row]);
    cell.TitleLabel.text = [titleLabel objectAtIndex:indexPath.row];
    cell.SubtitleLabel.text = [subtitleLabel objectAtIndex:indexPath.row];
    cell.myImageView.image = [UIImage imageNamed:@"DSCN5478.JPG"]

    return cell;
}

CustomCell.h

@interface CustomCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *TitleLabel;

@property (weak, nonatomic) IBOutlet UILabel *SubtitleLabel;

@property (weak, nonatomic) IBOutlet UIImageView *myImageView;

任何想法,为什么显示UIImageView但不显示UILabel

我正在使用Xcode 5并将目标IOS版本设置为7。

1 个答案:

答案 0 :(得分:0)

将您的UILabelUIImageView添加到自定义UITableViewCell的contentView。