Ho un tableView
con un custom cell
. Ho la possibilità di salvare tra i preferiti alcuni elementi e, quando ciò accade, voglio aggiungere una stella image
in cell
. Stavo provando a farlo, ma dopo che la stella appare, ho un problema. Penso che sia a causa di reusable
cell
ma non so come risolverlo. Il mio problema è:stars appear again on the other cells even if the word is not added on favorites.
Cella riutilizzabile personalizzata
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
dictionaryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell=[[dictionaryTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
if (tableView == self.searchDisplayController.searchResultsTableView)
{
cell.textLabel.text = [self.searchResult objectAtIndex:indexPath.row];
}
else
{
cell.word.text = self.tableData[indexPath.row];
BOOL isTheObjectThere = [self.favoriteArry containsObject:self.tableData[indexPath.row]];
if (isTheObjectThere==TRUE) {
cell.favImg.image=[UIImage imageNamed:@"[email protected]"];
}
}
return cell;
}
fatemi sapere se avete problemi. –