我使用以下代码尝试更新 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;
}
}
但是它不起作用,代码被调用但什么也不做。谁能解释当视图出现时我如何更新静态单元格的属性以实现类似上述的效果?
NSLog 语句说单元格为空。
谢谢
杰克