我创建了一个带有 UILabel 的自定义 UITableViewCell 。
在 cellForRowAtIndexPath 方法中,我初始化自定义单元格并给 UILabel 一个值。
加载自定义单元格时(单元格的高度高于默认单元格),我似乎无法给 UILabel 一个值。
SBDownloadCell.h
#import <UIKit/UIKit.h>
@interface SBDownloadCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UIProgressView *progressbar;
@property (weak, nonatomic) IBOutlet UILabel *details;
- (IBAction)pause:(id)sender;
@end
SBDownloadCell.m
#import "SBDownloadCell.h"
@implementation SBDownloadCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)pause:(id)sender {
}
@end
SBViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SBDownload";
SBDownloadCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[SBDownloadCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
SBDownload *dwnld = [[SBDownload alloc] init];
dwnld = [SBdownloads objectAtIndex:indexPath.row];
//cell.title.text = [dwnld name];
cell.title.text = @"Test";
cell.progressbar.progress = [dwnld percentDone];
cell.details.text = [NSString stringWithFormat:@"%f MB of %f MB completed, %@", [dwnld completed], [dwnld length], [dwnld eta]];
return cell;
}
故事板
我刚刚打破cell.title.text = @"Test";
,这仍然是我所看到的:
会是什么呢?
注意:我在 iOS7 中使用 Xcode DP-5