我已經創建了一個按鈕,將行狀態從「availible」更改爲「買過」的自定義單元格,並且我還有一個顯示狀態的UIImageview。當用戶按下按鈕時,我希望單元格重新繪製新的狀態。UITableviewController - 更新特定的單元格
我已經能夠在用戶將單元格滾動出視野後重新繪製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的代碼,這是一個委託調用,所以我的自定義銷售調用[委託buttonPushed:(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
的事情。什麼都不刷新細胞。經過幾個小時的閱讀,我認爲我做的都對,但沒有更新。
我很感激任何幫助。
我假設你嘗試過'[self.tableView setNeedsDisplay]',對吧? – dasblinkenlight
啊,是的,我也試過這個。 –