本文介绍了在集合视图单元格中设置文本时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在设置之后将值设为nslog它为NULL时,为什么这么说?
when I nslog the value after setting it it is NULL, any word why?
CustomCollectionVIewCell *cell =[[CustomCollectionVIewCell alloc]init];
NSString *name =[dict valueForKey:@"filterName"];//works
[cell.labelDisplay setText:name];//does not
NSLog(@"name = %@",cell.labelDisplay.text);
cell.isSelected=NO;
[_availableHealthFilters setObject:cell atIndexedSubscript:i];
推荐答案
在自定义单元格中初始化labelDisplay。
init your labelDisplay in custom cell.
//customColectionCell.h
@property(strong,nonomatic) NSString *labelText;
-(void)setCellLabelText:(NSString *)labelText;
//customCollectionCell.m
-(id)init{
//init cellLabel and addSubView to customCell
}
//Than set label in custom method
-(void)setCellLabelText:(NSString *)labelText{
_labelText = labelText;
sefl.labelDisplay.text = labelText;
}
这篇关于在集合视图单元格中设置文本时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!