想使用XIB创建自定义的UITableViewCell,但是不知道如何使用UITableViewController来回收它。怎么能做到这一点?
发布于 2018-01-23 14:20:54
如果使用的是iOS 5,可以使用
[self.tableView registerNib:[UINib nibWithNibName:@"nibname"
bundle:nil]
forCellReuseIdentifier:@"cellIdentifier"];
然后
cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];
发布于 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;
}
https://stackoverflow.com/questions/-100007220
复制相似问题