我在用Xcode 6我创建了我的应用程序UITableView
and 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
to a 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 的一个提示,告诉它“这可以在接口构建器上连接”。
界面生成器中的属性的类型为weak和IBOutlet的原因是,它们由故事板的视图控制器的视图本身保留,因此如果您在界面生成器中创建一个视图控制器,并添加一个视图,然后链接该视图在代码中,您的属性不必很强,因为它已经由视图之一保留。
您应该将这些属性更改为
@property (nonatomic, strong) SuggestedSeriesView *seriesOne;
@property (nonatomic, strong) SuggestedSeriesView *seriesTwo;
@property (nonatomic, strong) SuggestedSeriesView *seriesThree;
@property (nonatomic, strong) SuggestedSeriesView *seriesFour;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)