UITableView cell appearance update not working - iPhone
Posted
by
Jack Nutkins
on Stack Overflow
See other posts from Stack Overflow
or by Jack Nutkins
Published on 2012-06-19T09:01:48Z
Indexed on
2012/06/19
9:16 UTC
Read the original article
Hit count: 237
I have this piece of code which I'm using to set the alpha and accessibility of one of my tables cells dependent on a value stored in user defaults:
- (void) viewDidAppear:(BOOL)animated{
[self reloadTableData];
}
- (void) reloadTableData {
if ([[userDefaults objectForKey:@"canDeleteReceipts"] isEqualToString:@"0"])
{
NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:8];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
cell.contentView.alpha = 0.2;
cell.userInteractionEnabled = NO;
}
else
{
NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:8];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
cell.contentView.alpha = 1;
cell.userInteractionEnabled = YES;
}
if ([[userDefaults objectForKey:@"canDeleteMileages"] isEqualToString:@"0"])
{
NSIndexPath *path = [NSIndexPath indexPathForRow:1 inSection:8];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
cell.contentView.alpha = 0.2;
cell.userInteractionEnabled = NO;
}
else
{
NSIndexPath *path = [NSIndexPath indexPathForRow:1 inSection:8];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
cell.contentView.alpha = 1;
cell.userInteractionEnabled = YES;
}
if ([[userDefaults objectForKey:@"canDeleteAll"] isEqualToString:@"0"])
{
NSIndexPath *path = [NSIndexPath indexPathForRow:2 inSection:8];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
cell.contentView.alpha = 0.2;
cell.userInteractionEnabled = NO;
NSLog(@"In Here");
}
else
{
NSIndexPath *path = [NSIndexPath indexPathForRow:2 inSection:8];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
cell.contentView.alpha = 1;
cell.userInteractionEnabled = YES;
}
}
The value stored in userDefaults is '0' so the cell in section 8 row 2 should be greyed out and disabled, however this doesn't happen and the cell is still selectable with an alpha of 1... The log statement 'In Here' is called so it seems to be executing the right code, but that code doesn't seem to be doing anything. Can anyone explain what I've done wrong?
Thanks,
Jack
© Stack Overflow or respective owner