侧面菜单中的UITableView单元格消失

时间:2016-03-11 18:04:34

标签: ios tableview

我在旁边菜单中有一些奇怪的行为。这是它应该是什么样子:

enter image description here

点击组织右侧的按钮后,我使用此代码显示更多单元格

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

如果我从显示组织单元格的菜单导航,然后导航回菜单,则显示:

enter image description here

单元格显示为隐藏,但是当我将单元格设置为不隐藏时:         cell.hidden = NO; 它仍显示为隐藏。

关于发生了什么的任何想法?我的代码中没有任何地方可以将任何单元格设置为隐藏。

如果您需要更多代码,请告诉我们。

由于

以下是一些代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"MenuCell";
MenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
    cell = [[MenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

if (indexPath.section == 0)
{
    if (showOrgs && indexPath.row < organizations.count)
    {
        cell.label.text = [organizations objectAtIndex:indexPath.row];
        cell.label.textColor = [UIColor whiteColor];
        cell.leftImageView.hidden = YES;
        cell.contentView.backgroundColor = [UIColor colorWithHex:@"#ff6b01" alpha:1.0];
        cell.tag = 10002;
        cell.leftButton.hidden = YES;
        cell.righttButton.hidden = YES;
        cell.leftButton.enabled = NO;
        cell.righttButton.enabled = NO;
    }
    else if (showOrgs && indexPath.row >= organizations.count)
    {
        if (indexPath.row == organizations.count)
        {
            cell.label.text = [allUpper objectAtIndex:indexPath.row];//[organizations objectAtIndex:indexPath.row];
            cell.contentView.backgroundColor = [UIColor whiteColor];
            cell.label.textColor = [UIColor blackColor];
            cell.tag = 10001;
            [cell.leftImageView setImage:[UIImage imageNamed:@"dashboard"]];
            cell.leftImageView.hidden = NO;
        }
        else
        {
            cell.label.text = [allUpper objectAtIndex:indexPath.row];
            cell.label.textColor = [UIColor blackColor];
            cell.contentView.backgroundColor = [UIColor whiteColor];
            cell.tag = 10003;
            if ([[allUpper objectAtIndex:indexPath.row] isEqualToString:@"All Media"])
            {
                cell.leftImageView.image = [UIImage imageNamed:@"image-btn"];
                cell.leftImageView.hidden = NO;
            }
        }
    }
    NSLog(@"Row: %li", (long)indexPath.row);
    if (!showOrgs && [[upperSection objectAtIndex:indexPath.row] isEqualToString:@"Dashboard"])
    {
        cell.label.text = [upperSection objectAtIndex:indexPath.row];//[organizations objectAtIndex:indexPath.row];
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.tag = 10001;
        cell.hidden = NO;
        [cell.leftImageView setImage:[UIImage imageNamed:@"dashboard"]];
    }
    else if (!showOrgs && [[upperSection objectAtIndex:indexPath.row] isEqualToString:@"All Media"])
    {
        cell.label.text = [upperSection objectAtIndex:indexPath.row];
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.tag = 10003;
        cell.hidden = NO;
        if ([[upperSection objectAtIndex:indexPath.row] isEqualToString:@"All Media"])
        {
            cell.leftImageView.image = [UIImage imageNamed:@"image-btn"];
        }
    }
}

//    if (indexPath.section == 0 && showOrgs)
//        cell.label.text = [organizations objectAtIndex:indexPath.row];
else if (indexPath.section == 1)
    cell.label.text = [currentEvents objectAtIndex:indexPath.row];
else
    cell.label.text = [allEvents objectAtIndex:indexPath.row];

return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0 && !showOrgs)
    return upperSection.count;
else if (section == 0 && showOrgs)
    return allUpper.count;
else if (section == 1)
    return currentEvents.count;
else
    return allEvents.count;
}

1 个答案:

答案 0 :(得分:0)

我根据wottle的建议对块进行了一些更改,然后将其添加到块的末尾,以便不显示orgs

cell.leftButton.hidden = NO;
cell.righttButton.hidden = NO;
cell.leftButton.enabled = YES;
cell.righttButton.enabled = YES;
cell.leftImageView.hidden = NO;
cell.label.hidden = NO;
cell.label.textColor = [UIColor blackColor];

这似乎解决了它。谢谢你的帮助。