首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何回收从XIB创建的UITableViewCell对象?

如何回收从XIB创建的UITableViewCell对象?
EN

Stack Overflow用户
提问于 2018-01-23 06:02:59
回答 2查看 0关注 0票数 0

想使用XIB创建自定义的UITableViewCell,但是不知道如何使用UITableViewController来回收它。怎么能做到这一点?

EN

回答 2

Stack Overflow用户

发布于 2018-01-23 14:20:54

如果使用的是iOS 5,可以使用

[self.tableView registerNib:[UINib nibWithNibName:@"nibname" 
                                           bundle:nil] 
     forCellReuseIdentifier:@"cellIdentifier"];

然后

cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];
票数 0
EN

Stack Overflow用户

发布于 2018-01-23 15:17:23

若要在代码中使用单元格,请执行以下操作:

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *reuseIdentifier = @"blah"; //should match what you've set in Interface Builder
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"YourTableCellNib" owner:nil options:nil] objectAtIndex:0];
    }

    //set up cell

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

https://stackoverflow.com/questions/-100007220

复制
相关文章

相似问题

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