【问题标题】:UITableViewRow Height 0 appear different on ios7 and ios6UITableView 行高 0 在 ios 7 和 ios 6 上看起来不同
【发布时间】:2014-02-05 00:44:18
【问题描述】:

我正在研究 xcode 5 和 ios7,有一个包含 7 个部分的表格视图,我必须根据条件显示/隐藏三个部分,为此我已将该部分行的高度设置为 0,它运行良好在 ios7 上,但当我在 ios6 上运行时,也会查看高度为 0 的行。请让我知道我应该怎么做才能在 ios6 中防止这种情况发生。

IOS7 视图

在 ios6 中,显示在 ios 7 中隐藏的 paypal 行。选择否时,我不必显示此内容。

代码:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section==3 && !isadvisor)
    { return 0;}
    if(indexPath.section==4 && !isadvisor)
    {return 0;}
    if(indexPath.section==5 && !isadvisor)
    { return 0;}
    if (indexPath.section==0 && indexPath.row==0) {
        return 110;
    }
    if (indexPath.section==3 && indexPath.row==2) {
        return 125;
    }
    return 40;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{   return 7;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==0)     return 8;
    else if(section==1) return [arr3 count]+1;
    else if(section==2) return 1;
    else if(section==3) return 5;
    else if(section==4) return [arr1 count]+1;
    else if(section==5) return [arr2 count]+1;
    else if(section==6) return 1;

    else return 0;
    return 0;
}

请帮助我应该如何解决这个问题。 任何建议将不胜感激。 提前致谢。

【问题讨论】:

  • 您是否将元素放在高度为 0 的行上,高度不是基于单元格的高度?也许单元格的高度为零,但不是它们上面的元素。
  • @TotumusMaximus 是的,元素高度不是 0,但它在 io7 中正常工作,但在 ios6 上没有。

标签: iphone ios6 uitableview ios7 xcode5


【解决方案1】:

我不会让隐藏部分中的行高度为 0,而是更改部分的数量,以便这些部分根本不在 tableview 中。这将提高表格视图的性能,并消除单元格大小为 0 的任何怪异现象。

所以,在

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{   return 7;
}

您不会一直只返回 7:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{   return (isadvisor ? 7 : 4);
}

您还需要适应 section 中的变化,即 section 的行数和 indexPath 方法的单元格。

一种可能更简洁的方法是对视图控制器进行子类化,这样如果用户是顾问,则实例化一个使用 7 行逻辑的不同视图控制器,否则基本视图控制器使用 4 行逻辑。这会将您的“isadvisor”测试数量减少到只有一个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多