Я создал пользовательские ячейки с кнопкой, которая меняет состояние строки с «доступно» на «куплено», и у меня также есть UIImageview, которое показывает состояние.Я хочу, чтобы ячейка перерисовывалась с новым состоянием, когда пользователь нажимает кнопку.
Мне удалось получить перерисовываемый UIImage после того, как пользователь прокручивает ячейку вне поля зрения.Вот что у меня есть:
Инициализация
- (void)viewDidLoad
{
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = YES;
self.contentSizeForViewInPopover = CGSizeMake(600.0, 560.0);
//[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView setRowHeight:60];
[self.tableView setBackgroundColor:[UIColor blackColor]];
}
Получил только один раздел:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
И все элементы находятся в массиве "paketListe":
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [paketListe count];
}
Функция cellForRow вызывается только тогда, когда ячейка находится вне поля зрения и когда ячейка изначально рисуется.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"CellForRow called!");
PaketTableViewCell *cell = [[[PaketTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil] autorelease];
[cell setDelegate:self];
Paket *tempPaket = [paketListe objectAtIndex:[indexPath row]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *userDocumentsPath = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/%@/%@",userDocumentsPath, [tempPaket productID], [tempPaket previewPic]];
[cell setProductIndex:[indexPath row]];
//... Setting some Attributes in my custom cell, cut out for simplicity....
cell.backgroundColor = [UIColor clearColor];
return cell;
}
Код для Button, это вызов делегата, так что мой пользовательский вызов на продажу [делегат buttonPhed: (int)];
- (void) buttonPushed:(int) myProductIndex {
NSLog(@"Pushed: %@", [[paketListe objectAtIndex:myProductIndex] productID]);
CoreDataWrapper *tempCDW = [[CoreDataWrapper alloc] init];
[tempCDW initCoreData];
Paket *tempPaket = [paketListe objectAtIndex:myProductIndex];
//Doing some work in Core Data an my "paketListe" array. Left out for simplicity...
[tempCDW release];
//Here it begins....
[[self tableView] reloadData];
[[self tableView] beginUpdates];
[[self tableView] reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:myProductIndex inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[[self tableView] endUpdates];
}
Теперь я попытался перезагрузить с помощью различных команд ... Перезагрузить все с помощью reloadData
или begin-/endUpdate
,Ничто не освежает клетку.После нескольких часов чтения я думаю, что все сделал правильно, но без обновления.
Я ценю любую помощь.