我有一个 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/