[英]Custom UITableViewCell abandoned memory issue on Select
我使用自定義UITableView和自定義UITableViewCell在iOS上遇到問題。 當我在Xcode Instruments上運行應用程序時,每次從自定義TableView中選擇一個單元格時,我都會發現存在遺棄的內存問題。 請參閱下面的“儀器”的屏幕截圖。
http://i.stack.imgur.com/cKz22.png
以下是用於創建單元格的代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath2:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = [NSString stringWithFormat :@"cellID%i",indexPath.row];
customViewCell *cell = (customViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSInteger cellIndex = [indexPath row];
NSString* cellName = @"cell Name";
NSString* keyFile = @"0_48_video_1F0423D5-D2D7-466E-8D45-38C46E9B4425.mp4_1423522824.133377";
cell = [[customViewCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:cellIdentifier withKeyFile:keyFile andRicochetName:ricochetName fromTableViewController:self;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
我非常感謝有助於識別內存問題的任何專業知識。 請注意,該應用程序是基於ARC構建的。
非常感謝
如果你只需要傳遞keyFile名稱就可以使用這種方式。 確保在界面構建器中鏈接了keyFile
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath2:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"cellID";
customViewCell *cell = (customViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSInteger cellIndex = [indexPath row];
NSString* cellName = @"cell Name";
NSString* keyFile = @"0_48_video_1F0423D5-D2D7-466E-8D45-38C46E9B4425.mp4_1423522824.133377";
cell.keyFile=keyFile;
return cell;
}
將單元標識符更改為靜態字符串。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath2:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"your tableview Cell Identifier";
customViewCell *cell = (customViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSString* cellName = @"cell Name";
NSString* keyFile = @"0_48_video_1F0423D5-D2D7-466E-8D45-38C46E9B4425.mp4_1423522824.133377";
cell = [[customViewCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:cellIdentifier withKeyFile:keyFile andRicochetName:ricochetName fromTableViewController:self;
}
return cell;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.