ios - 同一 Controller 中的两个 UITableView

标签 ios uitableview ios7 xcode5

我认为这是一个错误。

iOS 7.0,XCode 5。

我的 Storyboard中有一个 TableView Controller 。我有一个带有“3”个静态单元格的 TableView。然后我添加了一个“ View ”,并在其中添加了一个带有动态原型(prototype)的 TableView。

当我尝试在动态表格中添加超过“3”个单元格时,应用程序崩溃了。

2016-01-10 08:18:21.358 Know[1381:a0b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** First throw call stack:
(
    0   CoreFoundation                      0x017535e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014d68b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01707a32 -[__NSArrayI objectAtIndex:] + 210
    3   UIKit                               0x00772983 -[UITableViewDataSource tableView:heightForHeaderInSection:] + 50
    4   UIKit                               0x00504fba -[UITableViewController tableView:heightForHeaderInSection:] + 61
    5   UIKit                               0x00333920 -[UITableView _delegateWantsHeaderForSection:] + 349
    6   UIKit                               0x0049a8f7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 133
    7   UIKit                               0x0049eb3d -[UITableViewRowData numberOfRows] + 98
    8   UIKit                               0x003274c2 -[UITableView noteNumberOfRowsChanged] + 120
    9   UIKit                               0x00326e6f -[UITableView reloadData] + 814
    10  UIKit                               0x0032a8d3 -[UITableView _reloadDataIfNeeded] + 65
    11  UIKit                               0x0032f4f4 -[UITableView layoutSubviews] + 36
    12  UIKit                               0x002b3dd7 -[UIView(CALayerDelegate) 

这是静态表的节数。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    if (tableView == self.ismTableView) {
        return 4;
    } else {
        // Static sections
        return 3;
    }
}

即使我正在检查表名并返回正确的计数,它似乎也没有接受它。

最佳答案

第二个 TableView 调用 tableView 方法的默认实现,此默认实现与 Controller (第一个 TableView )的 tableView 属性一起使用,它只有三个单元格。所以我猜你将不得不覆盖所有接收 indexPath 的方法

关于ios - 同一 Controller 中的两个 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34707088/

相关文章:

ios - self.tableView.indexPathForCell(cell) 返回错误的单元格?

ios - 使用 Swift 的序列化器 JSON 出错 - AutoreleasingUnsafePointer(有 1 个 child )

ios - IOS swift 中的 3D 立方体过渡

iOS 8 通知操作按钮不显示

java - 我可以在 Xcode 项目中使用 .java 文件中的方法吗?

ios - 自动布局: how to set the hugging & resistance priority for two multi-line UILabel stacked vertically?

ios - WKWebview:禁用交互和点击链接

ios - 直到滚动才显示 uitableview 标题背景

ios - 在ios 7中,UITableViewCell Accessory DetailDisclosureButton被分为两个不同的附属按钮

ios - 我的应用程序经常但随机地在应用程序加载时使整个手机崩溃