【发布时间】:2020-07-05 20:43:33
【问题描述】:
我一直在尝试通过我的 uiviewcontroller 将我的 tableviewcell 链接到我在 UIView 中的 tableview。虽然 tableview 在那里,但我的自定义 tableviewcell 没有加载。日志显示单元已初始化并填充
这是我在视图控制器中使用的代码,而表视图已经在 UIView 中设置
viewcontroller.m
- (void)viewDidLoad {
[super viewDidLoad];
barcodeItems = [NSArray arrayWithObjects:@"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday", nil];
NSLog(@"%@", barcodeItems);
[photoCaptureView.itemsTableView registerNib:[UINib nibWithNibName:@"BarcodeItemsTableViewCell" bundle:nil] forCellReuseIdentifier:@"BarcodeItemsCell"];
photoCaptureView.itemsTableView.rowHeight = 60;
photoCaptureView.itemsTableView.dataSource = self;
photoCaptureView.itemsTableView.delegate = self;
}
#pragma mark UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return barcodeItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Cell Initialized");
static NSString *cellIdentifier = @"BarcodeItemsCell";
BarcodeItemsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[BarcodeItemsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell...
NSLog(@"Cell Populated");
cell.barcodeLabel.text = @"TEST";
UIImage *btnImage = [UIImage imageNamed:@"barcodeIcon"];
[cell.leftButton setImage:btnImage forState:UIControlStateNormal];
return cell;
}
【问题讨论】:
-
您是否正确地将 tableview 的委托和数据源设置为您的视图控制器?
-
是否调用了
NSLog(@"Cell Populated");?reloadData何时调用 tableView?谁是数据源/代表(因为它是 CaptureView 的属性) -
只是自定义单元格没有显示还是默认 UITableViewCell 显示相同的行为?
-
所以我只是在 viewdidload 中设置了委托和数据源。
-
更新:日志显示单元格已初始化并填充,但显示空单元格。我提供了问题中的截图
标签: ios objective-c uitableview tableview