我正在使用Xcode 6,并且已经使用aUITableView
和a创建了我的应用程序custom Cell
。这是我的custom cell
@interface SuggestingTableViewCell : UITableViewCell
@property (nonatomic, weak) IBOutlet SuggestedSeriesView *seriesOne;
@property (nonatomic, weak) IBOutlet SuggestedSeriesView *seriesTwo;
@property (nonatomic, weak) IBOutlet SuggestedSeriesView *seriesThree;
@property (nonatomic, weak) IBOutlet SuggestedSeriesView *seriesFour;
@end
如您所见,我有四个IBOutets
到SuggestedSeriesView
,这是的子类UIView
。在这些TableView DataSource
方法中,我创建了这些方法,SuggestedSeriesView
并将其分配为:
cellIdentifier = suggestionCell;
SuggestingTableViewCell *suggesting = (SuggestingTableViewCell *)[tableView dequeueReusableCellWithIdentifier:suggestionCell];
Series *ser1 = series[0];
suggesting.seriesOne = [[SuggestedSeriesView alloc] initWithFrame:suggesting.seriesOne.bounds
andSeriesData:@{JV_SERIES_IMAGE_URL : ser1.imageURL,
JV_SERIES_TITLE : ser1.title}];
Series *ser2 = series[1];
suggesting.seriesTwo = [[SuggestedSeriesView alloc] initWithFrame:suggesting.seriesTwo.bounds
andSeriesData:@{JV_SERIES_IMAGE_URL : ser2.imageURL,
JV_SERIES_TITLE : ser2.title}];
Series *ser3 = series[2];
suggesting.seriesThree = [[SuggestedSeriesView alloc] initWithFrame:suggesting.seriesThree.bounds
andSeriesData:@{JV_SERIES_IMAGE_URL : ser3.imageURL,
JV_SERIES_TITLE : ser3.title}];
Series *ser4 = series[3];
suggesting.seriesFour = [[SuggestedSeriesView alloc] initWithFrame:suggesting.seriesFour.bounds
andSeriesData:@{JV_SERIES_IMAGE_URL : ser4.imageURL,
JV_SERIES_TITLE : ser4.title}];
编译器给我警告:
将保留对象分配给弱属性;对象将在分配后释放
为什么会发生这种情况,因为它没有SuggestedSeriesView
将保留的获取保留下来?cell
IBOutlet
谢谢您的帮助。
发生这种情况是因为您的属性很弱,这意味着它们将不会保留任何内容,它们只能引用内容。
IBOutlet等于void,这只是xcode告诉它“可以在接口生成器上连接”的提示。
界面构建器的属性类型为弱且IBOutlet的原因是,它们由情节提要的View控制器的视图本身保留,因此,如果您在界面构建器中创建视图控制器,然后添加视图,然后将其链接在代码中,您的属性不必很强,因为其中一个视图已经保留了该属性。
您应该将这些属性更改为
@property (nonatomic, strong) SuggestedSeriesView *seriesOne;
@property (nonatomic, strong) SuggestedSeriesView *seriesTwo;
@property (nonatomic, strong) SuggestedSeriesView *seriesThree;
@property (nonatomic, strong) SuggestedSeriesView *seriesFour;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句