简体   繁体   English

单击表格视图单元格时隐藏了UIImageView

[英]Hidden UIImageView while click the table view cell

In my application in one place i am display the UIImage and lable in a table view cell.It is working fine. 在我的应用程序的一个地方,我在一个表格视图单元格中显示UIImage和lable。它工作正常。 while click on the row i try to hidden one UIImage view and display another UIImage view. 在单击该行时,我尝试隐藏一个UIImage视图并显示另一个UIImage视图。

Code i try is 我尝试的代码是

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"AddFrdsGroup";
    AddFriendsCell *cell = (AddFriendsCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AddFriendsCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
    if(cell.chkAddFrdsYes.hidden==YES)
    {
        cell.chkAddFrdsNo.hidden=YES;
        cell.chkAddFrdsYes.hidden=NO;
    }
    else
    {
        cell.chkAddFrdsNo.hidden=YES;
        cell.chkAddFrdsYes.hidden=NO;
    }
}

Your message is not very clear but i'll try to help you with what I could understand. 您的信息不太清楚,但是我会尽力帮助您。 You need to get the cell you selected, not create or dequeue a new one. 您需要获取所选的单元,而不是创建或使新单元出队。 Try this instead. 试试这个吧。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AddFriendsCell *cell = (AddFriendsCell *)[tableView cellForRowAtIndexPath:indexPath];
    if(cell.chkAddFrdsYes.hidden==YES)
    {
        cell.chkAddFrdsNo.hidden=YES;
        cell.chkAddFrdsYes.hidden=NO;
    }
    else
    {
        cell.chkAddFrdsNo.hidden=YES;
        cell.chkAddFrdsYes.hidden=NO;
    }
}

In didSelectRowAtIndexPath method, save the indexPath of the row/cell selected in instance variable/property and call the reloadData method of table view. 在didSelectRowAtIndexPath方法中,将在实例变量/属性中选择的行/单元格的indexPath保存,并调用表视图的reloadData方法。 In tableView:cellForRowAtIndexPath: implementation (In table view datasource), do the hidden/unhidden activity of image views. 在tableView:cellForRowAtIndexPath:实现中(在表视图数据源中),执行图像视图的隐藏/未隐藏活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM