更改Cell AccessoryView

时间:2014-02-18 19:36:29

标签: ios objective-c uitableview accessoryview

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

以下是我尝试这样做的方式。如果隐藏了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];
    }

1 个答案:

答案 0 :(得分:1)

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