ios - UITableView 在未分配给父级 UIViewController View 属性时不滚动

标签 ios cocoa-touch uitableview scroll

我已将 UITableView 放入 UIViewController 中,并将代码从 UITableViewController 复制到我的 UIViewController 以使其通过 UITableViewControllers 默认实现实现“表数据协议(protocol)”,并关注 http://developer.apple.com/library/IOs/#documentation/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW10 s 章节“以编程方式创建 TableView ”(使用 ViewDidLoad 而不是 LoadView,因为我使用 IB 并且有一个 Nib ,我为名为 tableView 的 UITableView 创建了一个导出)。

现在在上面的链接章节中,UITableView 被分配给 self.view,这是 UIViewController 的 UIView 属性。然后滚动 UITableView 是有效的,但 UITableView 填满了整个屏幕,隐藏了其他 View 内容,例如 UIToolbar - 可能是因为它是分配给 View 属性后的唯一内容。

如果我省略分配,其他 View 内容就位,所有内容的大小都正确,但 UITableView 不会滚动。

如何使用具有静态内容(例如工具栏)的 UIVC 在 UIViewController 中实现 UITableView 的滚动?

相关代码如下:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView reloadData];
    //self.view = tableView;
}

最佳答案

如果您在界面生成器中添加的 View Controller 中有其他内容,那么这将是 UIViewController 的 .view 属性的一部分 - 当您将 TableView 分配给它时,您将删除所有这些内容。

如果您的表格 View 正常显示但没有滚动(选择如何?这行得通吗?)您可能已经禁用了用户交互。

您在评论中提到您的 TableView 中只有空单元格 - 我认为这是您的问题的原因。我刚刚创建了一个示例项目,我在其中添加了一个 TableView 作为 View Controller View 的 subview ,并且滚动很好——我在其中填充了 100 个虚拟行。如果我没有为数据源和委托(delegate)方法返回任何内容,那么 TableView 就不会滚动。

关于ios - UITableView 在未分配给父级 UIViewController View 属性时不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8460559/

相关文章:

ios - NSIndexPath 无法在具有 AlertView 功能的 DidSelectedRow 上工作

iOS 应用程序无法在 Xcode 中创建存档,但构建良好

ios - 升级到 Swift 3 后,属性 'self.delegate' 未在 super.init 调用中初始化

ios - 无法验证 MYAPP.app 的代码签名

ios - 检测 NSString 中的 URL

ios - 如何删除 iOS 组件中的边框

iphone - Qt 支持 iOS 吗?

iPhone : How to manage 130 images in ImageView?

swift - DidSelectRowAt 未在 UITableViewController 中调用

ios - 为什么我的嵌套 UITableView 不能正常弹跳?