每次我尝试向这个自定义的表视图单元格发送一个数组时,该数组都不发送(从array.count = 0可以看出,而它应该是9)。
这是我的cell.h
@interface Scell : UITableViewCell
...
@property (nonatomic, strong) NSMutableArray *lineInfo;
@end
cell.m
@implementation Scell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
self.lineInfo = [[NSMutableArray alloc]init];
//set up labels here, etc.
NSLog(@"Lines count: %li", self.lineInfo.count);
}
return self;
}
这是我尝试发送数据的地方。
setup.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Make cell
Scell *cell = (Scell *)[tableView dequeueReusableCellWithIdentifier:@"sCell" forIndexPath:indexPath];
object *temp = [self.array objectAtIndex:indexPath.row];
//labels, etc.
NSLog(@"count: %li", temp.lineInfo.count);
cell.lineInfo = temp.lineInfo;
return cell;
}
你知道为什么它不能发送吗?setup.m中的NSLog显示9,但Scell中的显示为0。
发布于 2019-05-24 03:16:52
在cell.m中,当单元格初始化时,将打印行数,因此此时此数组中没有值,这就是它打印零的原因。
在setup.m中的cellForRowAtIndexPath中,temp的lineInfo被分配给单元格的lineInfo属性。因此,cellForRowAtIndexPath打印正确的计数,但initWithStyle显示0。
希望这能有所帮助。
https://stackoverflow.com/questions/56281538
复制相似问题