我正在尝试自定义 UITableViewCell,但由于某种原因它显示为空白。有什么明显的我做错了吗?我已经从 Storyboard 中提取了 menuLabel 作为导出,因此它被正确绑定(bind), Storyboard 中的单元格链接到“MenuCell”类。
在我的 tableview Controller 中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MenuCell";
[self.tableView registerClass:[MenuCell class] forCellReuseIdentifier:CellIdentifier];
MenuCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
NSLog(@"creating a new cell");
cell = [[MenuCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"MenuCell"];
}
cell.menuLabel.text = @"Hello";
return cell;
}
最佳答案
你可以用这个
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MenuCell";
MenuCell *cell = (MenuCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
UINib* customCellNib = [UINib nibWithNibName:@"MenuCell" bundle:nil];
// Register this nib file with cell identifier.
[tableView registerNib: customCellNib forCellReuseIdentifier:CellIdentifier];
cell = (MenuCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
// Whatever you want
retrun cell;
}
希望这会有所帮助。快乐编码:P
关于ios - 扩展 TableViewCell 空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18847921/