Im using the following code to attempt to update several static cells in my UITableView:
- (void) viewDidAppear:(BOOL)animated{
[self reloadTableData];
}
- (void) reloadTableData {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:8];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
if ([[userDefaults objectForKey:@"canDeleteReceipts"] isEqualToString:@"0"])
{
cell.contentView.alpha = 0.2;
cell.userInteractionEnabled = NO;
}
else
{
cell.contentView.alpha = 1;
cell.userInteractionEnabled = YES;
}
path = [NSIndexPath indexPathForRow:1 inSection:8];
cell = [self.tableView cellForRowAtIndexPath:path];
if ([[userDefaults objectForKey:@"canDeleteMileages"] isEqualToString:@"0"])
{
cell.contentView.alpha = 0.2;
cell.userInteractionEnabled = NO;
}
else
{
cell.contentView.alpha = 1;
cell.userInteractionEnabled = YES;
}
path = [NSIndexPath indexPathForRow:2 inSection:8];
cell = [self.tableView cellForRowAtIndexPath:path];
if ([[userDefaults objectForKey:@"canDeleteAll"] isEqualToString:@"0"])
{
cell.contentView.alpha = 0.2;
cell.userInteractionEnabled = NO;
NSLog(@"%@", cell);
}
else
{
cell.contentView.alpha = 1;
cell.userInteractionEnabled = YES;
}
}
However it does’t work, the code is called but does nothing. Can anyone explain how I update the attributes of a static cell to achieve something like the above when the view appears?
The NSLog statement says that the cell is null.
Thanks
Jack
You need to write the code in
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPathinstead of yourreloadDatamethod.