ios - 更改单元格 AccessoryView

标签 ios objective-c uitableview accessoryview

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

这是我正在尝试的方法。如果 actionAlertBadge 被隐藏,索引 1 处的行的附属 View 应该是附属的,它确实是。如果 actionAlertBadge 未隐藏,则索引 1 处的行的附属 View 是 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/

相关文章:

ios - 应用/游戏发布后会变得更快吗?

ios - 如何将枚举添加到 Realm 模型? RLM对象?

objective-c - 关于applescript和expose的问题

ios - 在 iOS 中将 SKProduct 添加到 NSMutableArray 后出现 SIGABRT 错误

ios - UITableViewController 不显示自定义原型(prototype)单元格

ios - 打开带有预定义文本的 Facebook 应用程序以共享

ios - 调试时如何从命令行启动iOS应用?

iphone - UINavigationController 中的 UITableView

c++ - RootViewController 在其委托(delegate)外部访问时不会添加 subview

ios - 解析json并用tableview显示