У меня есть функция, которая вызывается кнопкой в ячейке табличного представления, после 15-20 вызовов этой функции (15 - 20 нажатий на кнопку) я получаю предупреждение памяти уровня 2.Без этой функции я, похоже, не получаю эту ошибку.
Я прочитал всю "ответственность за память", которая идет с разработкой приложений для iPhone, но моя неопытность мешает мне реализовать это в моей функциипоэтому я надеюсь, что кто-то там мог бы взглянуть на это и посмотреть, что может высосать всю память.
Функция (отредактировано: "(int) sender" -> "(id) sender ") :
- (void)addPoint:(id)sender {
if ([sender tag] == 0) {
[playerOneScore replaceObjectAtIndex:holeNum withObject:[NSNumber numberWithInt:[[playerOneScore objectAtIndex:holeNum] intValue] + 1]];
} if ([sender tag] == 1) {
[playerTwoScore replaceObjectAtIndex:holeNum withObject:[NSNumber numberWithInt:[[playerTwoScore objectAtIndex:holeNum] intValue] + 1]];
} if ([sender tag] == 2) {
[playerThreeScore replaceObjectAtIndex:holeNum withObject:[NSNumber numberWithInt:[[playerThreeScore objectAtIndex:holeNum] intValue] + 1]];
} if ([sender tag] == 3) {
[playerFourScore replaceObjectAtIndex:holeNum withObject:[NSNumber numberWithInt:[[playerFourScore objectAtIndex:holeNum] intValue] + 1]];
}
[tbl reloadData];
}
Буду признателен за любые указания о том, как освободить часть памяти из моей функции, функция бесполезна в том виде, в котором она сейчас себя ведет.
Примечание: я пробовал [button release]
, но это только создает ошибки и, похоже, не помогает моей ситуации с памятью.
Заранее спасибо, Тобиас Товедал
РЕДАКТИРОВАТЬ: cellForRowAtIndex:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
[cell.detailTextLabel setText:[NSString stringWithFormat:@"%@", [players objectAtIndex:indexPath.row]]];
[cell.textLabel setFont:[UIFont systemFontOfSize:50]];
UIButton *plusBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
plusBtn.frame = CGRectMake(255, 5, 60, 70);
[plusBtn setTitle:@"+" forState:UIControlStateNormal];
[plusBtn.titleLabel setFont:[UIFont systemFontOfSize:25]];
[plusBtn addTarget:self action:@selector(addPoint:) forControlEvents:UIControlEventTouchUpInside];
UIButton *minusBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
minusBtn.frame = CGRectMake(190, 5, 60, 70);
[minusBtn setTitle:@"-" forState:UIControlStateNormal];
[minusBtn.titleLabel setFont:[UIFont systemFontOfSize:25]];
[minusBtn addTarget:self action:@selector(removePoint:) forControlEvents:UIControlEventTouchUpInside];
plusBtn.tag = indexPath.row;
minusBtn.tag = indexPath.row;
if (indexPath.row == 0) {
[cell.textLabel setText:[[playerOneScore objectAtIndex:holeNum] stringValue]];
} if (indexPath.row == 1) {
[cell.textLabel setText:[[playerTwoScore objectAtIndex:holeNum] stringValue]];
} if (indexPath.row == 2) {
[cell.textLabel setText:[[playerThreeScore objectAtIndex:holeNum] stringValue]];
} if (indexPath.row == 3) {
[cell.textLabel setText:[[playerFourScore objectAtIndex:holeNum] stringValue]];
}
[cell.contentView addSubview:plusBtn];
[cell.contentView addSubview:minusBtn];
return cell;
}