我有一个自定义UITableViewCell
,其中包含四个视图
@interface SuggestingTableViewCell : UITableViewCell
@property (nonatomic, strong) IBOutlet SuggestedSeriesView *seriesOne;
@property (nonatomic, strong) IBOutlet SuggestedSeriesView *seriesTwo;
@property (nonatomic, strong) IBOutlet SuggestedSeriesView *seriesThree;
@property (nonatomic, strong) IBOutlet SuggestedSeriesView *seriesFour;
@end
SuggestedSeriesView
只是UIView的一个子类,有一些元素在其中放置代码
当调用DataSource方法tableView:cellForRowAtIndexPath:
时,我会像这样创建单元格
Genre *genre = [self.genres objectAtIndex:numberOfGenreIndex];
NSArray *series = self.seriesByGenres[genre.name];
cellIdentifier = suggestionCell;
SuggestingTableViewCell *tempCell = (SuggestingTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
Series *ser1 = series[0];
tempCell.seriesOne = [[SuggestedSeriesView alloc] initWithFrame:tempCell.seriesOne.bounds
andSeriesData:@{JV_SERIES_IMAGE_URL : ser1.imageURL,
JV_SERIES_TITLE : ser1.title}];
.... Continue creating serirsTwo/Three/Four..
但由于某种原因,内容没有显示。
Delegate
和DataSource
已连接SuggestedSeriesView
。"<SuggestedSeriesView: 0x7997b2b0; frame = (161 2; 157 197); clipsToBounds = YES; autoresize = RM+BM; layer = <CALayer:
0x7997b3e0&GT;&gt;”中,
"<SuggestedSeriesView: 0x79980090; frame = (161 201; 157 197); clipsToBounds = YES; autoresize = RM+BM; layer = <CALayer:
0x7997a250&GT;&gt;”中,
"<SuggestedSeriesView: 0x799769b0; frame = (2 201; 157 197); clipsToBounds = YES; autoresize = RM+BM; layer = <CALayer:
0x79981d00&GT;&gt;”中,
"<SuggestedSeriesView: 0x79976a20; frame = (2 2; 157 197); clipsToBounds = YES; autoresize = RM+BM; layer = <CALayer:
0x7997a4f0&GT;&gt;“中
感谢您的帮助,
EDIT1
只是搞乱代码,如果我将tabelView:cellForRowAtIndexPath
中的代码更改为addSubView
而不是等号,一切都按预期工作
Series *ser1 = series[0];
[tempCell.seriesOne addSubview:[[SuggestedSeriesView alloc] initWithFrame:tempCell.seriesOne.bounds
andSeriesData:@{JV_SERIES_IMAGE_URL : ser1.imageURL,
JV_SERIES_TITLE : ser1.title}]];
tempCell.seriesOne.clipsToBounds = YES;
.... Continue creating serirsTwo/Three/Four..
Dunno,如果有帮助
编辑2
好吧,我想我有点疯狂。
我一直在玩我的代码,登录一些情况并试图理解为什么会发生这种情况
我有这个日志:
Series *ser1 = series[0];
SuggestedSeriesView *suggSer1 = [[SuggestedSeriesView alloc] initWithFrame:tempCell.seriesOne.bounds
andSeriesData:@{JV_SERIES_IMAGE : ser1.imageData,
JV_SERIES_TITLE : ser1.title}];
tempCell.seriesOne = suggSer1;
NSLog(@"%@", tempCell.seriesOne.subviews);
这是日志
"<UIImageView: 0x7ae31530; frame = (0 0; 297 197); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7ae216f0>>", "<UIView: 0x7ae15ab0; frame = (0 0; 297 197); alpha = 0.45; layer = <CALayer: 0x7ae03a70>>", "<UILabel: 0x7ae0f2f0; frame = (19 157; 53.2568 17.145); text = '5 FACTS!'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7c634410>>"
正如您所看到的,所有内容都存在!但由于某种原因,它没有显示......
答案 0 :(得分:0)
这可能与此无关,但请尝试使您的IBOutlet属性变弱而不是强大。