在iOS应用程序中,我们必须先使用表视图注册nib文件,然后才能使用UITableView #dequeueReusableCellWithIdentifier.
例:
static Nsstring *myReuseIdentifier = @"MyReuseIdentifier"; UINib *cellNib = [UINib nibWithNibName:myReuseIdentifier bundle:nil]; [self.tableView registerNib:cellNib forCellReuseIdentifier:myReuseIdentifier];
有没有办法检查Nib是否已经注册了UITableView?
我有一个自定义单元格,我在我的应用程序中的几个控制器的各种表中使用.我想将一些代码移动到宏.就像是
-(CustomCell *)customCell:(UITableView *)tableView { static Nsstring *reuseIdentifier = @"MyReuseIdentifier"; if (![table hasAlreadyRegisterednib:reuseIdentifier]){ UINib *cellNib = [UINib nibWithNibName:reuseIdentifier bundle:nil]; [self.tableView registerNib:cellNib forCellReuseIdentifier:reuseIdentifier]; } CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; return cell; }
解决方法
我不确定它是否是你想要的,但是
-dequeueReusableCellWithIdentifier:
如果单元格未准备好重用,则返回nil.否则,它返回单元格,所以你可以简单地尝试.
原文地址:https://www.jb51.cc/c/118809.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。