【问题标题】:Xcode5 changes static table behavoir. How to fix?Xcode 5 改变了静态表的行为。怎么修?
【发布时间】:2013-09-26 04:25:05
【问题描述】:

此代码块在 Xcode 4.6 中完美运行,但在 Xcode5/IOS7 中不再适用。

在静态表中,节中的行是否可见(连同节标题)取决于 ID 行。如果以下代码被注释掉,视图控制器将加载,否则会生成:由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'* -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

视图控制器是一个 UITableView,除了 numberOfRowsInSection 之外的所有内容都被注释掉了。

任何想法如何恢复此功能?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 1)
    {
        if(ID == 1) return 0;
        else return 1;
    }
    else return 2;
}

谢谢

解决了!!!将“else return 2”替换为:

else return [super tableView:tableView numberOfRowsInSection:section];

【问题讨论】:

    标签: ios xcode uitableview ios7 xcode5


    【解决方案1】:

    您的标准行数是 2。您必须假设代码中的其他地方,即使您为索引为 1 的部分返回 0 或 1,您也可以访问第二行(索引为 1)。

    这可以解释为什么您的代码会导致此错误,而不是其他原因。

    【讨论】:

      猜你喜欢
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-07
      相关资源
      最近更新 更多