我遇到了与我的应用程序有关的问题,特别是与UITableView
及其UITableViewCells
。问题出在这里:我在UIView
内创建了一个UITableView
,并自定义了UITableViewCell
。我已经涉及到两个控制器:IOS5 - 自定义UITableViewCell不显示内容
- ListController.m
- ListCellController.m
在IB,我联系了小区的项目我的头文件中手动创建IBOutlets单元控制器。
下面是该ListCellController.h/M代码:
// .h
@class Item;
@interface ListCellController : UITableViewCell
@property (nonatomic, strong) Item *item;
@property (nonatomic, strong) IBOutlet UILabel *itemName;
@property (nonatomic, strong) IBOutlet UILabel *dates;
@property (nonatomic, strong) IBOutlet UILabel *itemId;
@end
// .m
// @synthetize stuff
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (!self) {
return nil;
}
self.textLabel.adjustsFontSizeToFitWidth = YES;
self.selectionStyle = UITableViewCellSelectionStyleGray;
return self;
}
- (void)setItem:(Item *)item
{
_item = item;
self.itemName.text = _list.itemName;
self.itemId.text = _list.itemId;
self.dates.text = [NSString stringWithFormat:@"Du %@ au %@", _list.date, _list.date];
}
而这里的ListController.h/M代码:
// .h
@interface ListController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *cellList;
}
@property (strong, nonatomic) IBOutlet UITableView *cellList;
@end
// .m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_list count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"List cell";
ListCellController *cell = [cellList dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[ListCellController alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.item = [_items objectAtIndex:indexPath.row];
cell.itemId.text = cell.item.itemId;
cell.itemName.text = cell.item.itemName;
cell.dates.text = [NSString stringWithFormat:@"From %@ to %@", cell.item.date, cell.item.date];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[cellList deselectRowAtIndexPath:indexPath animated:YES];
}
我的问题是,当我启动应用程序,我没有看到我的细胞。没有内容,没有错误,没有任何东西,空白单元格。
只要提一下,我也在这里使用故事板。
有没有人遇到过这个问题?我怎么能解决它?
谢谢。
你链接的IB委托和数据源?我没有看到你在代码中设置委托。 – Eric 2012-07-11 17:40:59
我只在IB中设置dataSource。看来我没有对代表做任何事情。但是我对IOS开发很陌生,在这种情况下我不知道该链接什么...... – 2012-07-11 17:53:34
无论哪个头类包含您的tableView Outlet也需要委托集,与数据源的方式相同。 – Eric 2012-07-11 17:57:42