简体   繁体   English

UINavigationController内部的UITableView不滚动

[英]UITableView inside UINavigationController doesn't scroll

I've got a MainWindow.xib file: 我有一个MainWindow.xib文件:

Inside there I've defined a UINavigationController as rootViewController of the Window. 在其中,我已将UINavigationController定义为Window的rootViewController。 The UINavigationController has a TableVC - item. UINavigationController有一个TableVC-项。

TableVC inherits from UITableViewController and implements the appropriated Delegate and Datasource. TableVC继承自UITableViewController并实现适当的Delegate和Datasource。

I overwrite 4 methods, viewDidload to initialize data and: 我覆盖了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;
}

I don't think there's anything wrong with this. 我不认为这有什么问题。

When I run the project, the NavigationBar and inside the TableView , populated with my data appears. 当我运行该项目时,将出现NavigationBar和TableView内,其中填充了我的数据。 But I can't scroll the Table!? 但是我无法滚动表格!?

Any hints are appreciated. 任何提示表示赞赏。

Check out labels: 签出标签:

- Scrolling Enabled
- User Interaction Enabled

for your tableView in your nib file (using IB of course) 在笔尖文件中用于tableView(当然使用IB)

EDIT: 编辑:

Iv just spotted Warkst's comment and I have realized you have a mistake an your code. iv刚刚发现了Warkst的注释,我意识到您的代码有误。 Im not sure if its causing the issue or not but you should fix it. 我不确定是不是导致问题的原因,但您应该修复它。

This line here: 这行在这里:

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

Should be 应该

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

Since you are using rows not sections. 由于您使用的是行而不是节。

This would mean you are getting the same data in each row since indexPath.row would always be zero. 这意味着您将在每一行中获得相同的数据,因为indexPath.row始终为零。


Firstly, I would suggest not using a UITableViewController . 首先,我建议不要使用UITableViewController Instead add a UITableView inside a UIViewController 's view. 而是在UIViewController的视图内添加UITableView This will make a much more flexible if you need to move the table around later. 如果您以后需要移动桌子,这将使灵活性更大。

Now there are a number of reasons why you might not be scrolling. 现在,有很多原因可能导致您无法滚动。

  1. It thinks it dont need to scroll, ie the content size isnt bigger than the frames size. 它认为它不需要滚动,即内容大小不大于框架大小。

    I dont think this is it because the table view sort this out itself. 我不认为这是因为表视图本身对此进行了排序。 But try logging the frame and the content size just incase. 但是请尝试记录框架和内容大小,以防万一。

  2. Its not receiving touch events. 它没有收到触摸事件。

    This could be because some other views is hijacking the events. 这可能是因为其他一些视图正在劫持事件。 Try overriding touches began touches ended etc, just log the event and call super. 尝试覆盖触摸,开始触摸,结束触摸等,只需记录事件并调用超级即可。 You will need to make a subclass of UITableView. 您将需要创建UITableView的子类。

    Otherwise there might be a funny view structure. 否则,可能会有一个有趣的视图结构。 If its outside of its parent's view frame it wont get touch events. 如果它不在其父视图框架之内,则不会发生触摸事件。 Try moving the whole thing outside the Navigation view int a clean view to see if that fixes it. 尝试将整个内容移到“导航”视图外的一个干净视图中,以查看是否可以解决问题。

  3. Scrolling is disabled. 滚动被禁用。

    Check buy loggin the property on the table view, scrollEnabled . 在表视图上scrollEnabled属性中检查buy loggin属性。

Thats all I can think of for now. 那就是我现在能想到的。 let me know how it goes. 让我知道事情的后续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM