首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扩展TableViewCell空白

扩展TableViewCell空白
EN

Stack Overflow用户
提问于 2013-09-17 10:54:15
回答 2查看 79关注 0票数 1

我试图定制一个UITableViewCell,但由于某种原因,它显示为空白。有什么明显的我做错了吗?我已经从故事板中提取了menuLabel作为一个出口,因此它被正确地绑定,并且故事板中的单元格被链接到类"MenuCell“。

在我的表视图控制器中

代码语言:javascript
复制
- (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;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-17 11:08:30

你可以用这个

代码语言:javascript
复制
    - (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

票数 2
EN

Stack Overflow用户

发布于 2013-09-17 11:01:43

用这个..。

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *cellIdentifier = @"MenuCell";
        MenuCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if (cell == nil)
        {
            cell = [[MenuCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            cell = (MenuCell *)[[[NSBundle mainBundle] loadNibNamed:@"MenuCell" owner:self options:nil] objectAtIndex:0];

        }
        cell.menuLabel.text = @"Hello";
        return cell;
    }

我希望这会有帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18847921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档