0
How to create a UITableView
, where cells keep the text bold until touched, and save this change?
For example, when we receive a message on Facebook the text on UITableViewCell
is in bold, after touching the cell and see and return to UITableView
, cell text no longer in bold.
Example, Image Below:
Below the code I tried but it didn’t work:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
.
.
.
//Implementation
.
.
.
// Atualiza o estado de NÃO LIDO para LIDO no banco de dados
[[fetchedObjects objectAtIndex:indexPath.row ] setValue:@"1" forKey:@"lido"];
NSError*error;
// Escreve no banco a alteração
[context save:&error];
for (int index = 0; index<[fetchedObjects count]; index++) {
NSLog(@"%@",[[fetchedObjects objectAtIndex:index]valueForKey:@"lido"]);
.
.
.
// Implementation
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
.
.
.
//Implmentation
.
.
.
//Verifica o estado e faz a alteração na fonte da célula
if ([[arrayProcessosLocal objectAtIndex:indexPath.row ] valueForKey:@"lido"] == 1) {
//Torna fonte bold
cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
[cell.textLabel setText:[NSString stringWithFormat:@"%@ - %@", [processosLocal valueForKey:@"processo"],[processosLocal valueForKey:@"data_pdf"]]];
return cell;
}else{
// Exibe a fonte normal caso o valor de "lido" seja 0 (zero)
[cell.textLabel setText:[NSString stringWithFormat:@"%@ - %@", [processosLocal valueForKey:@"processo"], [processosLocal valueForKey:@"data_pdf"]]];
return cell;
}
How to do this process?
I already have a persistence in core data, and I did a logic similar to yours, but it didn’t work... I’ll try with your code and I’ll tell you if it worked or not! Thank you!
– Tiago Amaral
I put the excerpt of the code I did, take a look and see what you think... I haven’t run the test with the code you gave me, but I’m going to do Aja!
– Tiago Amaral
it seems that when it detects if, it enters that pattern and determines the value of the source for all of the following cells :/. The same result I had with your code I had with my... did you see my code? When I put an exclamation (reverse the logical appraisal of if) if(![myObject isSaved]) it puts everything in bold, even reading from the bank that some are already READ it puts them back in bold.
– Tiago Amaral
I found the problem, I was making a wrong comparison between the types and the Xcode can not check this error because it is only possible to know the TYPE in run time! I will post the answer!
– Tiago Amaral