简体   繁体   English

奇怪的Tableview滚动行为

[英]Strange Tableview scrolling behavior

I've got two views, each of which contains a tableview. 我有两个视图,每个视图都包含一个表视图。 They are identical in every respect except the height. 除了高度,它们在各个方面都是相同的。 They are each fed data from the same entity (currently filled with gibberish) in my Core Data store. 它们分别来自我的核心数据存储区中同一实体(当前充满乱码)的数据。

One of them works perfectly when scrolled, the other behaves differently. 它们中的一个在滚动时工作完美,另一个在行为上有所不同。 The problem is that the cells scroll past the top section header. 问题是单元格滚动经过顶部标题。 Succeeding section titles bump older ones up as expected, and the header title slides up along with the cells. 成功的节标题会像预期的那样使较旧的标题升高,并且标题标题与单元格一起向上滑动。

Here are a couple of screenshots that I hope will illustrate the issue: 以下是一些屏幕快照,希望可以说明问题:

First, the one that works properly: 首先,可以正常工作的一个:

在此处输入图片说明

"A" is the top section header, and the cells don't scroll past it. “ A”是顶部标题,单元格不会滚动通过它。

The next two shots are of the tableview that's behaving weirdly. 接下来的两个镜头是怪异的tableview。 I've added some arrows to show what's happening: 我添加了一些箭头来显示正在发生的事情:

在此处输入图片说明

在此处输入图片说明

I've compared the settings in the Attributes Inspector, and unless I've overlooked something, they appear identical. 我已经比较了“属性”检查器中的设置,除非忽略了某些内容,否则它们看起来是相同的。

Anyone have any ideas? 有人有想法么?

Thanks! 谢谢!

Edit: 编辑:

Here's the code from the associated UIViewController which is the delegate and the datasource for the TableView: 以下是关联的UIViewController中的代码,该代码是TableView的委托和数据源:

//
//  AvsAViewController.m
//  WMDGx
//
//  Created by Tim Jones on 2/6/14.
//  Copyright (c) 2014 TDJ. All rights reserved.
//

#import "AvsAViewController.h"

@interface AvsAViewController ()
{
    NSFetchedResultsController *frc;
}

@end

@implementation AvsAViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self refreshData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[frc sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id<NSFetchedResultsSectionInfo> sectionInfo = [[frc sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

// Customize the appearance of table view cells.
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {

    // Configure the cell to show the activity's name
    ListActivity *thisActivity = [frc objectAtIndexPath:indexPath];
    cell.textLabel.text = thisActivity.activityName;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"aVSaCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    [self configureCell:cell atIndexPath:indexPath];

    cell.textLabel.textColor = [UIColor redColor];
    NSAttributedString *attString;
    attString = cell.textLabel.attributedText;
    return cell;
}


//     Section Label

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *sectionLabel = [[[frc sections] objectAtIndex:section]name];
    return [sectionLabel uppercaseString];
}

-(void) refreshData
{
    //This was the turning point for proper MR grouping. The two Properties (activityCategory and activityName) are used as Sort descriptors in the underlying core data methods

    frc = [ListActivity MR_fetchAllSortedBy:@"activityCategory,activityName"
                                  ascending:YES withPredicate:nil
                                    groupBy:@"activityCategory"
                                   delegate:nil];
    [self.myTableView reloadData];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

确保在“属性”检查器中为该UITableView选择了“ Clip Subviews”,并且在代码中某处未将表的clipsToBounds设置为NO

I resolved the issue by simply deleting the TableView and dragging in a new one, wiring it up. 我解决了这个问题,只需删除TableView并拖动一个新的,将其连接起来即可。 The problem is therefore fixed, but I have no idea what caused it. 因此,该问题已解决,但我不知道是什么原因引起的。

Thanks to @drhr, who commented, and all others who took a look! 感谢@drhr,他发表了评论,并感谢所有其他人!

Edit: 编辑:

Just wondering if anyone else has run across this problem. 只是想知道是否有人遇到过这个问题。 I just had it repeat on another tableview, and had to resolve it as above. 我只是在另一个表视图上重复了它,并且不得不如上所述解决它。 FWIW, I'm using Xcode 5, and developing an iPhone app. FWIW,我正在使用Xcode 5,并正在开发iPhone应用程序。

I guess fixed is good, but it would be nice to actually know what caused the problem. 我认为已修复是好的,但实际上知道是什么引起了该问题会很好。

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

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