我有一个表格视图,其中有一行在两个附件视图之间切换。问题是,当我显示非默认的附件视图时,无法将其切换回原来的视图。

这就是我要尝试的方法。如果actionAlertBadge隐藏,则索引1行的附件视图应该是附件。如果未隐藏actionAlertBadge,则索引1处的行的附件视图为actionAlertBadge。如果附件是actionAlertBadge,则如果选择了索引1的行,则应更改为附件,但没有。

在cellForRowAtIndexPath中

if (!(indexPath.row == 1))
    {
        cell.accessoryView = accessory;
    }

    badgeNumber = [NSString stringWithFormat:@"%d", [[UIApplication sharedApplication]applicationIconBadgeNumber]];

    actionAlertBadge = [JSCustomBadge customBadgeWithString:badgeNumber];
    actionAlertBadge.frame = CGRectMake(83, 6, 30, 30);

    if ([badgeNumber isEqualToString:@"0"])
    {
        actionAlertBadge.hidden = YES;
    }

    if (actionAlertBadge.hidden == NO)
    {
        if (indexPath.row == 1)
        {
            cell.accessoryView = actionAlertBadge;
        }
    }
    else
    {
        if (indexPath.row == 1)
        {
            cell.accessoryView = accessory;
        }
    }

并在didSelectRowAtIndexPath中
else if (indexPath.row == 1)
    {
        ActionAlertsIpad *actionAlerts = [[ActionAlertsIpad alloc]initWithStyle:UITableViewStyleGrouped];
        WebViewControllerIpad *wvc = [[WebViewControllerIpad alloc]init];
        [actionAlerts setWebViewController:wvc];
        actionAlerts.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [[UAPush shared] resetBadge];
        actionAlertBadge.hidden = YES;
        [self.navigationController pushViewController:actionAlerts animated:YES];
    }

最佳答案

我通过在行选择代码中添加[tableView reloadData];来解决此问题。

关于ios - 更改单元格AccessoryView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21863645/

10-09 00:38