【问题标题】:UITableView inside UINavigationController doesn't scrollUINavigationController 内的 UITableView 不滚动
【发布时间】:2012-01-06 14:57:59
【问题描述】:

我有一个 MainWindow.xib 文件:

在里面我定义了一个 UINavigationController 作为 Window 的 rootViewController。 UINavigationController 有一个 TableVC - 项。

TableVC 继承自 UITableViewController 并实现相应的 Delegate 和 Datasource。

我覆盖了4个方法,viewDidload来初始化数据和:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return [data count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.textLabel.text = [data objectAtIndex:indexPath.row];
    return cell;
}

我不认为这有什么问题。

当我运行项目时,会出现 NavigationBar 和 TableView 内部,其中填充了我的数据。但是我不能滚动表格!?

感谢任何提示。

【问题讨论】:

  • 请问您为什么喜欢将数据显示为每一行的单独部分,而不是单独的一个部分?
  • 表格视图是如何添加到导航控制器的?

标签: iphone objective-c uitableview ios4


【解决方案1】:

查看标签:

- Scrolling Enabled
- User Interaction Enabled

为您的 nib 文件中的 tableView(当然使用 IB)

【讨论】:

  • 我已经检查过了,我已经检查了两个字段。我确实在那里改变了一些东西以防止出现警告。我已禁用 - 定义上下文 - 私有上下文 也许它与这些设置有关?
【解决方案2】:

编辑:

我刚刚发现 Warkst 的评论,我意识到您的代码有误。我不确定它是否会导致问题,但您应该修复它。

这里的这一行:

cell.textLabel.text = [data objectAtIndex:indexPath.row];

应该是

cell.textLabel.text = [data objectAtIndex:indexPath.section];

因为您使用的是行而不是部分。

这意味着您在每一行中获得相同的数据,因为indexPath.row 将始终为零。


首先,我建议不要使用UITableViewController。而是在UIViewController 的视图中添加UITableView。如果您稍后需要移动桌子,这将使您更加灵活。

现在您可能不滚动的原因有很多。

  1. 它认为它不需要滚动,即内容大小不大于框架大小。

    我不认为这是因为表格视图会自行解决。但是尝试记录框架和内容大小以防万一。

  2. 它没有接收到触摸事件。

    这可能是因为其他一些视图正在劫持事件。尝试覆盖触摸开始触摸结束等,只需记录事件并调用超级。你需要创建一个 UITableView 的子类。

    否则可能会有一个有趣的视图结构。如果它在其父视图框架之外,它将不会获得触摸事件。尝试将整个导航视图移到一个干净的视图之外,看看是否可以修复它。

  3. 滚动已禁用。

    在表格视图上查看购买登录属性,scrollEnabled

暂时能想到的就这么多。告诉我进展如何。

【讨论】:

  • 错误的地方,点击错误,移动了评论。
猜你喜欢
  • 1970-01-01
  • 2019-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-23
相关资源
最近更新 更多