我在cellForRowAtIndexPath
之外访问细胞标签时遇到问题。首先在cellForRowAtIndexPath
我隐藏cell.lblempName.hidden = YES;
以下是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.tblemplist.tableFooterView=self.footerView;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
EmployeeCell *cell = (EmployeeCell *) [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"EmployeeCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (EmployeeCell *) currentObject;
cell.backgroundColor=[UIColor clearColor];
}
}
}
NSMutableDictionary *detailsdict=[empArray objectAtIndex:indexPath.row];
cell.lblTitle.text = [detailsdict objectForKey:@"empTitle"];
cell.lblItemprice.text = [detailsdict objectForKey:@"empId"];
cell.lblempName.hidden = YES;
}
在页脚中我添加了一个视图并放置了一个按钮。当我点击按钮lblempName
应该取消隐藏。
- (IBAction)btnApplyClicked:(id)sender {
// How to unHide cell.lblempName.hidden = NO;
}
请帮我找到解决方案。 TIA
答案 0 :(得分:0)
EmployeeCell *cell = (EmployeeCell *)[self.tableView cellForRowAtIndexPath:indexPath];
UILabel *label = cell.lblempName;
label.hidden = NO;
但更好的是修改你的数据,因为一旦单元格滚出视图并再次返回,标签将再次可见,因为它将再次构建。
答案 1 :(得分:0)
创建一个bool属性BOOL isEmpNameHidden;
在 viewDidLoad
中,设置isEmpNameHidden = YES;
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Your existing code here
....
cell.lblempName.hidden = isEmpNameHidden;
}
然后根据按钮点击取消隐藏
- (IBAction)btnApplyClicked:(id)sender {
isEmpNameHidden = NO;
[self.tblemplist reloadData]
}